Skip to content

Commit 3bf52ff

Browse files
committed
Fix crashes due to conflict in method resolution I assume; fix Charger flickering
1 parent c776942 commit 3bf52ff

10 files changed

Lines changed: 42 additions & 67 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ yarn_mappings=1.21.1+build.3
77
loader_version=0.16.10
88
fabric_version=0.115.1+1.21.1
99

10-
mod_version=1.0.0-alpha.17
10+
mod_version=1.0.0-alpha.18
1111
maven_group=falseresync.vivatech
1212
archives_base_name=vivatech
1313

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"values": [
3+
"vivatech:gadget"
4+
]
5+
}

src/main/java/falseresync/vivatech/common/blockentity/BaseAppliance.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public BaseAppliance(BlockEntityType<?> type, BlockPos pos, BlockState state) {
1818
super(type, pos, state);
1919
}
2020

21+
@Override
22+
public BlockPos getAppliancePos() {
23+
return getPos();
24+
}
25+
2126
@Override
2227
public void onGridConnected() {
2328
connected = true;

src/main/java/falseresync/vivatech/common/blockentity/ChargerBlockEntity.java

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package falseresync.vivatech.common.blockentity;
22

33
import falseresync.vivatech.common.Vivatech;
4-
import falseresync.vivatech.common.item.VivatechItems;
5-
import falseresync.vivatech.common.power.Appliance;
4+
import falseresync.vivatech.common.item.VivatechItemTags;
65
import net.minecraft.block.Block;
76
import net.minecraft.block.BlockState;
8-
import net.minecraft.block.entity.BlockEntity;
97
import net.minecraft.entity.player.PlayerEntity;
108
import net.minecraft.item.ItemStack;
119
import net.minecraft.nbt.NbtCompound;
@@ -14,21 +12,19 @@
1412
import net.minecraft.network.packet.Packet;
1513
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
1614
import net.minecraft.registry.RegistryWrapper;
17-
import net.minecraft.server.world.ServerWorld;
1815
import net.minecraft.util.Hand;
1916
import net.minecraft.util.math.BlockPos;
20-
import net.minecraft.util.math.ChunkSectionPos;
2117
import org.jetbrains.annotations.Nullable;
2218

23-
public class ChargerBlockEntity extends BlockEntity implements Ticking, Appliance {
19+
public class ChargerBlockEntity extends BaseAppliance implements Ticking {
2420
protected ItemStack stack = ItemStack.EMPTY;
25-
protected boolean connected = false;
26-
protected boolean operational = false;
21+
protected boolean canCharge = false;
22+
protected boolean couldChargeLastTick = false;
2723
protected boolean charging = false;
28-
protected int gridCheckCooldown = 0;
2924

3025
public ChargerBlockEntity(BlockPos pos, BlockState state) {
3126
super(VivatechBlockEntities.CHARGER, pos, state);
27+
setAcceptableVoltage(220, 240);
3228
}
3329

3430
@Override
@@ -37,52 +33,30 @@ public void tick() {
3733
return;
3834
}
3935

40-
if (operational) {
41-
if (Vivatech.getChargeManager().isGadgetFullyCharged(stack)) {
42-
if (charging) {
43-
charging = false;
36+
canCharge = isOperational() && !Vivatech.getChargeManager().isGadgetFullyCharged(stack);
37+
38+
if (canCharge) {
39+
if (couldChargeLastTick) {
40+
if (!charging) {
41+
charging = true;
4442
markDirty();
4543
}
46-
return;
47-
}
4844

49-
if (!charging) {
50-
charging = true;
45+
Vivatech.getChargeManager().charge(stack, 1, null);
46+
}
47+
} else {
48+
if (charging) {
49+
charging = false;
5150
markDirty();
5251
}
53-
54-
Vivatech.getChargeManager().charge(stack, 1, null);
5552
}
56-
}
5753

58-
@Override
59-
public void onGridConnected() {
60-
connected = true;
61-
}
62-
63-
@Override
64-
public void onGridDisconnected() {
65-
connected = false;
66-
}
67-
68-
@Override
69-
public void onGridFrozen() {
70-
operational = false;
54+
couldChargeLastTick = canCharge;
7155
}
7256

7357
@Override
7458
public float getElectricalCurrent() {
75-
return charging ? - 0.5f : 0;
76-
}
77-
78-
@Override
79-
public void gridTick(float voltage) {
80-
if (connected && gridCheckCooldown == 0) {
81-
operational = voltage > 210 && voltage < 250;
82-
gridCheckCooldown = 10;
83-
} else if (gridCheckCooldown > 0) {
84-
gridCheckCooldown -= 1;
85-
}
59+
return canCharge ? -0.5f : 0;
8660
}
8761

8862
public ItemStack getStackCopy() {
@@ -95,7 +69,7 @@ public boolean isCharging() {
9569

9670
public void exchangeOrDrop(PlayerEntity player, Hand hand) {
9771
var stackInHand = player.getStackInHand(hand);
98-
if (stackInHand.isOf(VivatechItems.GADGET) || stackInHand.isEmpty()) {
72+
if (stackInHand.isIn(VivatechItemTags.CHARGEABLE) || stackInHand.isEmpty()) {
9973
player.setStackInHand(hand, stack);
10074
stack = stackInHand;
10175
} else {

src/main/java/falseresync/vivatech/common/blockentity/GeneratorBlockEntity.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
import net.minecraft.block.entity.BlockEntity;
88
import net.minecraft.util.math.BlockPos;
99

10-
public class GeneratorBlockEntity extends BlockEntity implements Ticking, Appliance {
10+
public class GeneratorBlockEntity extends BaseAppliance implements Ticking {
1111
private boolean generating = true;
12-
private boolean connected = false;
1312

1413
public GeneratorBlockEntity(BlockPos pos, BlockState state) {
1514
super(VivatechBlockEntities.GENERATOR, pos, state);
@@ -21,27 +20,17 @@ public void tick() {
2120
return;
2221
}
2322

24-
if (connected) {
23+
if (isConnected()) {
2524
var facing = getCachedState().get(GearboxBlock.FACING);
2625
var gearboxState = world.getBlockState(pos.offset(facing));
2726
var wind_turbineState = world.getBlockState(pos.offset(facing, 2));
2827
generating = gearboxState.isOf(VivatechBlocks.GEARBOX) && wind_turbineState.isOf(VivatechBlocks.WIND_TURBINE);
28+
} else if (generating) {
29+
generating = false;
2930
}
3031
}
31-
3232
@Override
3333
public float getElectricalCurrent() {
3434
return generating ? 2 : 0;
3535
}
36-
37-
@Override
38-
public void onGridConnected() {
39-
connected = true;
40-
}
41-
42-
@Override
43-
public void onGridDisconnected() {
44-
connected = false;
45-
generating = false;
46-
}
4736
}

src/main/java/falseresync/vivatech/common/blockentity/StaticCompensatorBlockEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import net.minecraft.block.entity.BlockEntity;
66
import net.minecraft.util.math.BlockPos;
77

8-
public class StaticCompensatorBlockEntity extends BlockEntity implements Ticking, Appliance {
8+
public class StaticCompensatorBlockEntity extends BaseAppliance implements Ticking {
99
public StaticCompensatorBlockEntity(BlockPos pos, BlockState state) {
1010
super(VivatechBlockEntities.STATIC_COMPENSATOR, pos, state);
1111
}

src/main/java/falseresync/vivatech/common/item/VivatechItemTags.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
public class VivatechItemTags {
1010
public static final TagKey<Item> FOCUSES = TagKey.of(RegistryKeys.ITEM, vtId("focuses"));
1111
public static final TagKey<Item> GADGETS = TagKey.of(RegistryKeys.ITEM, vtId("gadgets"));
12+
public static final TagKey<Item> CHARGEABLE = TagKey.of(RegistryKeys.ITEM, vtId("chargeable"));
1213

1314
public static void init() {
1415
}

src/main/java/falseresync/vivatech/common/power/Appliance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public interface Appliance {
66
/**
77
* Must not change
88
*/
9-
BlockPos getPos();
9+
BlockPos getAppliancePos();
1010

1111
/**
1212
* Only called when first connected. <br/>

src/main/java/falseresync/vivatech/common/power/Grid.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,21 @@ private void onVertexAdded(GridVertex vertex, boolean shouldInitialize) {
173173
if (vertex.appliance() != null) {
174174
if (!appliances.containsValue(vertex.appliance())) {
175175
onApplianceAdded(vertex.appliance(), shouldInitialize);
176-
var appliancePos = vertex.appliance().getPos();
176+
var appliancePos = vertex.appliance().getAppliancePos();
177177
trackedChunks.computeIfAbsent(new ChunkPos(appliancePos), key -> new ObjectOpenHashSet<>()).add(appliancePos);
178178
}
179179
}
180180
}
181181

182182
private void onApplianceAdded(Appliance appliance, boolean shouldInitialize) {
183-
appliances.put(appliance.getPos(), appliance);
183+
appliances.put(appliance.getAppliancePos(), appliance);
184184
if (shouldInitialize) {
185185
appliance.onGridConnected();
186186
}
187187
}
188188

189189
private void onVertexRemoved(GridVertex vertex, boolean removeGridIfEmpty) {
190-
onVertexRemoved(vertex.pos(), vertex.appliance() != null ? vertex.appliance().getPos() : null, removeGridIfEmpty);
190+
onVertexRemoved(vertex.pos(), vertex.appliance() != null ? vertex.appliance().getAppliancePos() : null, removeGridIfEmpty);
191191
}
192192

193193
private void onVertexRemoved(BlockPos pos, @Nullable BlockPos appliancePos, boolean removeGridIfEmpty) {
@@ -271,7 +271,7 @@ private void refreshApplianceReferences() {
271271
var appliancesToUpdate = new ObjectOpenHashSet<ReferenceObjectPair<Appliance, GridVertex>>();
272272
for (GridVertex oldVertex : graph.vertexSet()) {
273273
if (oldVertex.appliance() != null) {
274-
var appliance = PowerSystem.APPLIANCE.find(world, oldVertex.appliance().getPos(), null);
274+
var appliance = PowerSystem.APPLIANCE.find(world, oldVertex.appliance().getAppliancePos(), null);
275275
appliancesToUpdate.add(ReferenceObjectPair.of(appliance, oldVertex));
276276
}
277277
}

src/main/java/falseresync/vivatech/datagen/VivatechItemTagProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public VivatechItemTagProvider(FabricDataOutput output, CompletableFuture<Regist
1818
protected void configure(RegistryWrapper.WrapperLookup arg) {
1919
getOrCreateTagBuilder(VivatechItemTags.FOCUSES).add(FOCUSES);
2020
getOrCreateTagBuilder(VivatechItemTags.GADGETS).add(VivatechItems.GADGET);
21+
getOrCreateTagBuilder(VivatechItemTags.CHARGEABLE).add(VivatechItems.GADGET);
2122
}
2223

2324
public static final Item[] FOCUSES = new Item[] {

0 commit comments

Comments
 (0)