diff --git a/README.md b/README.md new file mode 100644 index 00000000..291380bb --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +
+ +

Create: The Factory Must Grow

+ CurseForge + Modrinth + Discord +
+ Heavy Engineering & Oil For The Create Mod +
+ +
+ +## Info + +Create is by default a steam/clockpunk mod and most addons aim to expand this part of Create and do that pretty well, +we thought the next natural expansion would be moving on from steampunk to dieselpunk. +We believe that create could be later used not just as a single steampunk tech mod, +but due to its modularity and polishedness, it is a perfect base for other tech mods aiming to Create (get it) something new with it, +essentially using it as a library. +We wanna be the first ones to try and prove this concept. + +
+ +## Features + +* Large Distilleries +* Realistic Electricity +* Steel Mills +* Concrete +* Electrolyzers +* Steel +* Aluminum +* Cast Iron +* Lead +* Sulfur +* OIL!!! +* Quad Potato Cannon +* Flamethrowers +* And more.. + +
+ +![refinery image](https://cdn.modrinth.com/data/USgVjXsk/images/16f8c83fbec919fdc571236d62434b2d8050cf11.png) + diff --git a/src/main/java/com/drmangotea/tfmg/content/electricity/base/ElectricBlockEntity.java b/src/main/java/com/drmangotea/tfmg/content/electricity/base/ElectricBlockEntity.java index 06d2051b..a425d3fc 100644 --- a/src/main/java/com/drmangotea/tfmg/content/electricity/base/ElectricBlockEntity.java +++ b/src/main/java/com/drmangotea/tfmg/content/electricity/base/ElectricBlockEntity.java @@ -25,7 +25,6 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric, public ElectricBlockValues data = new ElectricBlockValues(getPos()); - public ElectricBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); data.connectNextTick = true; @@ -34,7 +33,6 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric, } } - @Override public void addBehaviours(List behaviours) { } @@ -44,32 +42,10 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric, return level; } - @Override - public boolean destroyed() { - return data.destroyed; - } - - @Override - public ElectricalNetwork getOrCreateElectricNetwork() { - if (level.getBlockEntity(BlockPos.of(data.electricalNetworkId)) instanceof IElectric) { - return TFMG.NETWORK_MANAGER.getOrCreateNetworkFor((IElectric) level.getBlockEntity(BlockPos.of(data.electricalNetworkId))); - } else { - ElectricNetworkManager.networks.get(getLevel()) - .remove(data.electricalNetworkId); - return TFMG.NETWORK_MANAGER.getOrCreateNetworkFor(this); - } - } - @Override public void lazyTick() { super.lazyTick(); - if (data.failTimer >= 4) { - this.blockFail(); - data.failTimer = 0; - sendStuff(); - } else if ((data.voltage > getMaxVoltage() && getMaxVoltage() > 0) || (getCurrent() > getMaxCurrent()&&getMaxCurrent()>0)) { - data.failTimer++; - } + lazyTickElectricity(); } @Override @@ -78,127 +54,11 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric, } - - - @Override - public float resistance() { - return 0; - } - - @Override - public int voltageGeneration() { - - int voltageGeneration = 0; - - for (Direction direction : Direction.values()) { - if (hasElectricitySlot(direction)) { - - if (level.getBlockEntity(getBlockPos().relative(direction)) instanceof VoltageAlteringBlockEntity be) - if (be.getData().getId() != getData().getId()) - if (be.getData().getVoltage() != 0) - if (be.hasElectricitySlot(direction)) { - voltageGeneration = Math.max(voltageGeneration, be.getOutputVoltage()); - data.getsOutsidePower = true; - } - } - } - - if (voltageGeneration == 0) - data.getsOutsidePower = false; - - return voltageGeneration; - } - - - - @Override - public int powerGeneration() { - - int powerGeneration = 0; - - for (Direction direction : Direction.values()) { - if (hasElectricitySlot(direction)) { - - if (level.getBlockEntity(getBlockPos().relative(direction)) instanceof VoltageAlteringBlockEntity be&&be.canWork()) { - - if (be.getData().getId() != getData().getId()) - if (be.getData().getVoltage() != 0) - if (be.hasElectricitySlot(direction)) { - powerGeneration = Math.max(powerGeneration, be.getPowerUsage()) + 1; - if(powerGeneration>be.getNetworkPowerGeneration()) { - powerGeneration = 0; - be.data.updatePowerNextTick=true; - } - } - } - } - } - - return powerGeneration; - } - - @Override - public int frequencyGeneration() { - return 0; - } - - @Override - public void updateNextTick() { - data.updateNextTick = true; - } - - @Override - public void updateNetwork() { - getOrCreateElectricNetwork().updateNetwork(); - if (level instanceof ServerLevel serverLevel) - CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition),new NetworkUpdatePacket(BlockPos.of(getPos()))); - sendData(); - } - @Override public void sendStuff() { sendData(); } - @Override - public void setVoltage(int newVoltage) { - - - - if (canBeInGroups()) { - data.voltage = (int) (((float) resistance() / data.group.resistance) * (float) data.voltageSupply); - return; - } - data.voltage = newVoltage; - } - - @Override - public void setFrequency(int newFrequency) { - data.frequency = newFrequency; - } - - @Override - public void setNetworkResistance(int newUsage) { - data.networkResistance = newUsage; - } - - @Override - public int getNetworkResistance() { - return data.networkResistance; - } - - - @Override - public void setNetwork(long network) { - this.data.electricalNetworkId = network; - if (network != getPos()) - ElectricNetworkManager.networks.get(getLevel()) - .remove(getPos()); - } - - public boolean networkUndersupplied() { - return getNetworkPowerUsage() > data.networkPowerGeneration; - } @Override @@ -209,67 +69,28 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric, @Override public void remove() { super.remove(); + onRemoved(); - this.data.destroyed = true; - for (Direction d : Direction.values()) { - if (hasElectricitySlot(d)) - if (getLevelAccessor().getBlockEntity(BlockPos.of(getPos()).relative(d)) instanceof IElectric be && be.hasElectricitySlot(d.getOpposite())) { - ElectricNetworkManager.networks.get(getLevel()) - .remove(be.getPos()); - be.setNetwork(be.getPos()); - be.onPlaced(); - be.updateNextTick(); - } - } - if (data.electricalNetworkId != getPos()) - getOrCreateElectricNetwork().getMembers().remove(this); -// - if (data.electricalNetworkId == getPos()) - ElectricNetworkManager.networks.get(getLevel()) - .remove(getData().getId()); } @Override public void tick() { super.tick(); - if (data.checkForLoopsNextTick) { - getOrCreateElectricNetwork().checkForLoops(getBlockPos()); - data.checkForLoopsNextTick = false; - } - if (data.connectNextTick) { - onPlaced(); - data.connectNextTick = false; - } - if (data.updateNextTick) { - updateNetwork(); - data.updateNextTick = false; - } - - if (data.updatePowerNextTick) { - updateUnpowered(new ArrayList<>()); - data.updatePowerNextTick = false; - } - if (data.setVoltageNextTick) { - setVoltage(data.voltageSupply); - data.setVoltageNextTick = false; - } + tickElectricity(); } @Override protected void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) { super.write(compound,registries , clientPacket); + writeElectricity(compound,clientPacket); - compound.putInt("GroupId", data.group.id); - compound.putFloat("GroupResistance", data.group.resistance); } @Override protected void read(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) { super.read(compound,registries , clientPacket); - data.group = new ElectricalGroup(compound.getInt("GroupId")); - data.group.resistance = compound.getFloat("GroupResistance"); - if (!clientPacket) - data.connectNextTick = true; + readElectricity(compound,clientPacket); + } } diff --git a/src/main/java/com/drmangotea/tfmg/content/electricity/base/IElectric.java b/src/main/java/com/drmangotea/tfmg/content/electricity/base/IElectric.java index 969d4083..c2c7b9fd 100644 --- a/src/main/java/com/drmangotea/tfmg/content/electricity/base/IElectric.java +++ b/src/main/java/com/drmangotea/tfmg/content/electricity/base/IElectric.java @@ -11,6 +11,8 @@ import net.createmod.catnip.theme.Color; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.ChunkPos; @@ -26,9 +28,19 @@ public interface IElectric { LevelAccessor getLevelAccessor(); - boolean destroyed(); + default boolean destroyed(){ + return getData().destroyed(); + } - ElectricalNetwork getOrCreateElectricNetwork(); + default ElectricalNetwork getOrCreateElectricNetwork() { + if (getLevelAccessor().getBlockEntity(BlockPos.of(getData().electricalNetworkId)) instanceof IElectric) { + return TFMG.NETWORK_MANAGER.getOrCreateNetworkFor((IElectric) getLevelAccessor().getBlockEntity(BlockPos.of(getData().electricalNetworkId))); + } else { + ElectricNetworkManager.networks.get(getLevelAccessor()) + .remove(getData().electricalNetworkId); + return TFMG.NETWORK_MANAGER.getOrCreateNetworkFor(this); + } + } default boolean hasElectricitySlot(Direction direction) { return true; @@ -43,35 +55,82 @@ public interface IElectric { getData().electricalNetworkId = getPos(); network.add(this); - BlockPos pos = BlockPos.of(getPos()); + getData().checkForLoopsNextTick = true; getOrCreateElectricNetwork().checkForLoops(BlockPos.of(getPos())); /// //// - // for (Direction d : Direction.values()) { - // if (hasElectricitySlot(d)) - // if (getLevelAccessor().getBlockEntity(pos.relative(d)) instanceof IElectric be) { - // if (be.hasElectricitySlot(d.getOpposite())) { - // if (!be.destroyed()) { -// -// - // for(IElectric member : be.getOrCreateElectricNetwork().members){ - // network.add(member); - // member.setNetwork(this.getData().electricalNetworkId); -// - // } -// - // } - // } - // } - // } updateNextTick(); onConnected(); sendStuff(); } + default void onRemoved(){ + this.getData().destroyed = true; + for (Direction d : Direction.values()) { + if (hasElectricitySlot(d)) + if (getLevelAccessor().getBlockEntity(BlockPos.of(getPos()).relative(d)) instanceof IElectric be && be.hasElectricitySlot(d.getOpposite())) { + ElectricNetworkManager.networks.get(getLevelAccessor()) + .remove(be.getPos()); + be.setNetwork(be.getPos()); + be.onPlaced(); + be.updateNextTick(); + } + } + if (getData().electricalNetworkId != getPos()) + getOrCreateElectricNetwork().getMembers().remove(this); +// + if (getData().electricalNetworkId == getPos()) + ElectricNetworkManager.networks.get(getLevelAccessor()) + .remove(getData().getId()); + } + + default void readElectricity(CompoundTag compound, boolean clientPacket){ + getData().group = new ElectricalGroup(compound.getInt("GroupId")); + getData().group.resistance = compound.getFloat("GroupResistance"); + if (!clientPacket) + getData().connectNextTick = true; + } + + default void writeElectricity(CompoundTag compound, boolean clientPacket){ + compound.putInt("GroupId", getData().group.id); + compound.putFloat("GroupResistance", getData().group.resistance); + } + + default void tickElectricity(){ + if (getData().checkForLoopsNextTick) { + getOrCreateElectricNetwork().checkForLoops(getBlockPos()); + getData().checkForLoopsNextTick = false; + } + if (getData().connectNextTick) { + onPlaced(); + getData().connectNextTick = false; + } + if (getData().updateNextTick) { + updateNetwork(); + getData().updateNextTick = false; + } + + if (getData().updatePowerNextTick) { + updateUnpowered(new ArrayList<>()); + getData().updatePowerNextTick = false; + } + if (getData().setVoltageNextTick) { + setVoltage(getData().voltageSupply); + getData().setVoltageNextTick = false; + } + } + default void lazyTickElectricity(){ + if (getData().failTimer >= 4) { + this.blockFail(); + getData().failTimer = 0; + sendStuff(); + } else if ((getData().voltage > getMaxVoltage() && getMaxVoltage() > 0) || (getCurrent() > getMaxCurrent()&&getMaxCurrent()>0)) { + getData().failTimer++; + } + } default int getMaxVoltage() { return 0; @@ -106,6 +165,10 @@ public interface IElectric { } + default BlockPos getBlockPos(){ + return BlockPos.of(getPos()); + } + default void updateUnpowered(List alreadyChecked) { alreadyChecked.add(BlockPos.of(getPos())); updateNextTick(); @@ -276,15 +339,69 @@ public interface IElectric { } - float resistance(); + default float resistance(){ + return 0; + } - int voltageGeneration(); - int powerGeneration(); + default int voltageGeneration() { - int frequencyGeneration(); + int voltageGeneration = 0; + + for (Direction direction : Direction.values()) { + if (hasElectricitySlot(direction)) { + + if (getLevelAccessor().getBlockEntity(getBlockPos().relative(direction)) instanceof VoltageAlteringBlockEntity be) + if (be.getData().getId() != getData().getId()) + if (be.getData().getVoltage() != 0) + if (be.hasElectricitySlot(direction)) { + voltageGeneration = Math.max(voltageGeneration, be.getOutputVoltage()); + getData().getsOutsidePower = true; + } + } + } + + if (voltageGeneration == 0) + getData().getsOutsidePower = false; + + return voltageGeneration; + } + + + + default int powerGeneration() { + + int powerGeneration = 0; + + for (Direction direction : Direction.values()) { + if (hasElectricitySlot(direction)) { + + if (getLevelAccessor().getBlockEntity(getBlockPos().relative(direction)) instanceof VoltageAlteringBlockEntity be&&be.canWork()) { + + if (be.getData().getId() != getData().getId()) + if (be.getData().getVoltage() != 0) + if (be.hasElectricitySlot(direction)) { + powerGeneration = Math.max(powerGeneration, be.getPowerUsage()) + 1; + if(powerGeneration>be.getNetworkPowerGeneration()) { + powerGeneration = 0; + be.data.updatePowerNextTick=true; + } + } + } + } + } + + return powerGeneration; + } + + default int getNetworkResistance() { + return getData().networkResistance; + } + + default boolean networkUndersupplied() { + return getNetworkPowerUsage() > getData().networkPowerGeneration; + } - int getNetworkResistance(); default int getMaxAmps() { return (int) getCurrent(); @@ -307,20 +424,44 @@ public interface IElectric { return current; } - void updateNextTick(); + default void updateNextTick(){ + getData().updateNextTick = true; + } - void updateNetwork(); + default void updateNetwork() { + getOrCreateElectricNetwork().updateNetwork(); + if (getLevelAccessor() instanceof ServerLevel serverLevel) + CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(getBlockPos()),new NetworkUpdatePacket(BlockPos.of(getPos()))); + sendStuff(); + } void sendStuff(); - void setVoltage(int newVoltage); - void setFrequency(int newFrequency); - - void setNetworkResistance(int newUsage); + default void setVoltage(int newVoltage) { - void setNetwork(long network); + + if (canBeInGroups()) { + getData().voltage = (int) (((float) resistance() / getData().group.resistance) * (float) getData().voltageSupply); + return; + } + getData().voltage = newVoltage; + } + + + default void setNetworkResistance(int newUsage){ + getData().networkResistance = newUsage; + } + + + + default void setNetwork(long network) { + getData().electricalNetworkId = network; + if (network != getPos()) + ElectricNetworkManager.networks.get(getLevelAccessor()) + .remove(getPos()); + } default boolean canBeInGroups() { return false; diff --git a/src/main/java/com/drmangotea/tfmg/content/electricity/base/KineticElectricBlockEntity.java b/src/main/java/com/drmangotea/tfmg/content/electricity/base/KineticElectricBlockEntity.java index 80c36ace..93f65cde 100644 --- a/src/main/java/com/drmangotea/tfmg/content/electricity/base/KineticElectricBlockEntity.java +++ b/src/main/java/com/drmangotea/tfmg/content/electricity/base/KineticElectricBlockEntity.java @@ -26,10 +26,6 @@ import java.util.List; public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity implements IElectric, IHaveGoggleInformation, IHaveHoveringInformation { public ElectricBlockValues data = new ElectricBlockValues(getPos()); - int powerPercentage = 100; - - int timer = 0; - public KineticElectricBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); @@ -39,42 +35,16 @@ public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity imp } } - - @Override - public void addBehaviours(List behaviours) { - } - @Override public LevelAccessor getLevelAccessor() { return level; } - @Override - public boolean destroyed() { - return data.destroyed; - } - - @Override - public ElectricalNetwork getOrCreateElectricNetwork() { - if (level.getBlockEntity(BlockPos.of(data.electricalNetworkId)) instanceof IElectric) { - return TFMG.NETWORK_MANAGER.getOrCreateNetworkFor((IElectric) level.getBlockEntity(BlockPos.of(data.electricalNetworkId))); - } else { - ElectricNetworkManager.networks.get(getLevel()) - .remove(data.electricalNetworkId); - return TFMG.NETWORK_MANAGER.getOrCreateNetworkFor(this); - } - } @Override public void lazyTick() { super.lazyTick(); - if (data.failTimer >= 4) { - this.blockFail(); - data.failTimer = 0; - sendStuff(); - } else if ((data.voltage > getMaxVoltage() && getMaxVoltage() > 0) || (getCurrent() > getMaxCurrent() && getMaxCurrent() > 0)) { - data.failTimer++; - } + lazyTickElectricity(); } @Override @@ -83,123 +53,13 @@ public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity imp } - @Override - public float resistance() { - return 0; - } - - @Override - public int voltageGeneration() { - - int voltageGeneration = 0; - - for (Direction direction : Direction.values()) { - if (hasElectricitySlot(direction)) { - - if (level.getBlockEntity(getBlockPos().relative(direction)) instanceof VoltageAlteringBlockEntity be) - if (be.getData().getId() != getData().getId()) - if (be.getData().getVoltage() != 0) - if (be.hasElectricitySlot(direction)) { - voltageGeneration = Math.max(voltageGeneration, be.getOutputVoltage()); - data.getsOutsidePower = true; - } - } - } - - if (voltageGeneration == 0) - data.getsOutsidePower = false; - - return voltageGeneration; - } - - - @Override - public int powerGeneration() { - - int powerGeneration = 0; - - for (Direction direction : Direction.values()) { - if (hasElectricitySlot(direction)) { - - if (level.getBlockEntity(getBlockPos().relative(direction)) instanceof VoltageAlteringBlockEntity be && be.canWork()) { - - if (be.getData().getId() != getData().getId()) - if (be.getData().getVoltage() != 0) - if (be.hasElectricitySlot(direction)) { - powerGeneration = Math.max(powerGeneration, be.getPowerUsage()) + 1; - if (powerGeneration > be.getNetworkPowerGeneration()) { - powerGeneration = 0; - be.data.updatePowerNextTick = true; - } - } - } - } - } - - return powerGeneration; - } - - @Override - public int frequencyGeneration() { - return 0; - } - - @Override - public void updateNextTick() { - data.updateNextTick = true; - } - - @Override - public void updateNetwork() { - getOrCreateElectricNetwork().updateNetwork(); - if (level instanceof ServerLevel serverLevel) - CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition),new NetworkUpdatePacket(BlockPos.of(getPos()))); - sendData(); - } - @Override public void sendStuff() { sendData(); } - @Override - public void setVoltage(int newVoltage) { - if (canBeInGroups()) { - data.voltage = (int) (((float) resistance() / data.group.resistance) * (float) data.voltageSupply); - return; - } - data.voltage = newVoltage; - } - - @Override - public void setFrequency(int newFrequency) { - data.frequency = newFrequency; - } - - @Override - public void setNetworkResistance(int newUsage) { - data.networkResistance = newUsage; - } - - @Override - public int getNetworkResistance() { - return data.networkResistance; - } - - - @Override - public void setNetwork(long network) { - this.data.electricalNetworkId = network; - if (network != getPos()) - ElectricNetworkManager.networks.get(getLevel()) - .remove(getPos()); - } - - public boolean networkUndersupplied() { - return getNetworkPowerUsage() > data.networkPowerGeneration; - } @Override @@ -210,68 +70,26 @@ public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity imp @Override public void remove() { super.remove(); - - this.data.destroyed = true; - for (Direction d : Direction.values()) { - if (hasElectricitySlot(d)) - if (getLevelAccessor().getBlockEntity(BlockPos.of(getPos()).relative(d)) instanceof IElectric be && be.hasElectricitySlot(d.getOpposite())) { - ElectricNetworkManager.networks.get(getLevel()) - .remove(be.getPos()); - be.setNetwork(be.getPos()); - be.onPlaced(); - be.updateNextTick(); - } - } - if (data.electricalNetworkId != getPos()) - getOrCreateElectricNetwork().getMembers().remove(this); -// - if (data.electricalNetworkId == getPos()) - ElectricNetworkManager.networks.get(getLevel()) - .remove(getData().getId()); + onRemoved(); } @Override public void tick() { super.tick(); - if (data.checkForLoopsNextTick) { - getOrCreateElectricNetwork().checkForLoops(getBlockPos()); - data.checkForLoopsNextTick = false; - } - if (data.connectNextTick) { - onPlaced(); - data.connectNextTick = false; - } - if (data.updateNextTick) { - updateNetwork(); - data.updateNextTick = false; - } - - if (data.updatePowerNextTick) { - updateUnpowered(new ArrayList<>()); - data.updatePowerNextTick = false; - } - if (data.setVoltageNextTick) { - setVoltage(data.voltageSupply); - data.setVoltageNextTick = false; - } + tickElectricity(); } @Override protected void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) { super.write(compound,registries , clientPacket); - - compound.putInt("GroupId", data.group.id); - compound.putFloat("GroupResistance", data.group.resistance); + writeElectricity(compound,clientPacket); } @Override protected void read(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) { super.read(compound,registries , clientPacket); - data.group = new ElectricalGroup(compound.getInt("GroupId")); - data.group.resistance = compound.getFloat("GroupResistance"); - if (!clientPacket) - data.connectNextTick = true; + readElectricity(compound,clientPacket); } @@ -281,7 +99,7 @@ public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity imp if (this instanceof RegularEngineBlockEntity) notifyNetworkAboutSpeedChange(); - timer = 0; + } diff --git a/src/main/java/com/drmangotea/tfmg/content/electricity/connection/copycat_cable/CopycatCableBlockEntity.java b/src/main/java/com/drmangotea/tfmg/content/electricity/connection/copycat_cable/CopycatCableBlockEntity.java index 53d18f1f..2bb60b3b 100644 --- a/src/main/java/com/drmangotea/tfmg/content/electricity/connection/copycat_cable/CopycatCableBlockEntity.java +++ b/src/main/java/com/drmangotea/tfmg/content/electricity/connection/copycat_cable/CopycatCableBlockEntity.java @@ -31,8 +31,6 @@ public class CopycatCableBlockEntity extends CopycatBlockEntity implements IElec public ElectricBlockValues data = new ElectricBlockValues(getPos()); - int powerPercentage = 100; - boolean setNextTick = true; public CopycatCableBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); data.connectNextTick = true; @@ -40,38 +38,19 @@ public class CopycatCableBlockEntity extends CopycatBlockEntity implements IElec data.group = new ElectricalGroup(-1); } } - @Override - public boolean hasCustomMaterial() { - return !AllBlocks.COPYCAT_BASE.has(getMaterial()); - } - @Override - public void addBehaviours(List behaviours) { - } @Override public LevelAccessor getLevelAccessor() { return level; } - @Override - public boolean destroyed() { - return data.destroyed; - } - @Override - public ElectricalNetwork getOrCreateElectricNetwork() { - if (level.getBlockEntity(BlockPos.of(data.electricalNetworkId)) instanceof IElectric) { - return TFMG.NETWORK_MANAGER.getOrCreateNetworkFor((IElectric) level.getBlockEntity(BlockPos.of(data.electricalNetworkId))); - } else { - ElectricNetworkManager.networks.get(getLevel()) - .remove(data.electricalNetworkId); - return TFMG.NETWORK_MANAGER.getOrCreateNetworkFor(this); - } - } + @Override public void lazyTick() { super.lazyTick(); + lazyTickElectricity(); } @Override @@ -80,116 +59,14 @@ public class CopycatCableBlockEntity extends CopycatBlockEntity implements IElec } - @Override - public float resistance() { - return 0; - } - @Override - public int voltageGeneration() { - int voltageGeneration = 0; - - for (Direction direction : Direction.values()) { - if (hasElectricitySlot(direction)) { - - if (level.getBlockEntity(getBlockPos().relative(direction)) instanceof VoltageAlteringBlockEntity be) - if (be.getData().getId() != getData().getId()) - if (be.getData().getVoltage() != 0) - if (be.hasElectricitySlot(direction)) { - voltageGeneration = Math.max(voltageGeneration, be.getOutputVoltage()); - data.getsOutsidePower = true; - } - } - } - - if (voltageGeneration == 0) - data.getsOutsidePower = false; - - return voltageGeneration; - } - - @Override - public int powerGeneration() { - - int powerGeneration = 0; - - for (Direction direction : Direction.values()) { - if (hasElectricitySlot(direction)) { - - if (level.getBlockEntity(getBlockPos().relative(direction)) instanceof VoltageAlteringBlockEntity be) { - if (be.getData().getId() != getData().getId()) - if (be.getData().getVoltage() != 0) - if (be.hasElectricitySlot(direction)) { - powerGeneration = Math.max(powerGeneration, be.getPowerUsage()) + 1; - } - } - } - } - - return powerGeneration; - } - - @Override - public int frequencyGeneration() { - return 0; - } - - @Override - public void updateNextTick() { - data.updateNextTick = true; - } - - @Override - public void updateNetwork() { - getOrCreateElectricNetwork().updateNetwork(); - if (level instanceof ServerLevel serverLevel) - CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition),new NetworkUpdatePacket(BlockPos.of(getPos()))); - - sendData(); - } @Override public void sendStuff() { sendData(); } - @Override - public void setVoltage(int newVoltage) { - if (canBeInGroups()) { - data.voltage = (int) (((float) resistance() / data.group.resistance) * (float) data.voltageSupply); - return; - } - data.voltage = newVoltage; - } - - @Override - public void setFrequency(int newFrequency) { - data.frequency = newFrequency; - } - - @Override - public void setNetworkResistance(int newUsage) { - data.networkResistance = newUsage; - } - - @Override - public int getNetworkResistance() { - return data.networkResistance; - } - - @Override - public void setNetwork(long network) { - this.data.electricalNetworkId = network; - if (network != getPos()) - ElectricNetworkManager.networks.get(getLevel()) - .remove(getPos()); - } - - public boolean networkUndersupplied() { - return getNetworkPowerUsage() > data.networkPowerGeneration; - } - @Override public long getPos() { @@ -199,52 +76,20 @@ public class CopycatCableBlockEntity extends CopycatBlockEntity implements IElec @Override public void remove() { super.remove(); - this.data.destroyed = true; - for (Direction d : Direction.values()) { - if (hasElectricitySlot(d)) - if (getLevelAccessor().getBlockEntity(BlockPos.of(getPos()).relative(d)) instanceof IElectric be && be.hasElectricitySlot(d.getOpposite())) { - ElectricNetworkManager.networks.get(getLevel()) - .remove(be.getPos()); - be.setNetwork(be.getPos()); - be.onPlaced(); - be.updateNextTick(); - } - } - if (data.electricalNetworkId != getPos()) - getOrCreateElectricNetwork().getMembers().remove(this); - - if (data.electricalNetworkId == getPos()) - ElectricNetworkManager.networks.get(getLevel()) - .remove(getData().getId()); + onRemoved(); } @Override public void tick() { super.tick(); - if (data.connectNextTick) { - onPlaced(); - data.connectNextTick = false; - } - if (data.updateNextTick) { - updateNetwork(); - data.updateNextTick = false; - } - if (data.setVoltageNextTick) { - setVoltage(data.voltageSupply); - data.setVoltageNextTick = false; - } - //if(setNextTick) { - // setMaterial(TFMGBlocks.COPYCAT_CABLE_BASE.getDefaultState()); - // setNextTick = false; - //} + tickElectricity(); } @Override protected void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) { super.write(compound,registries , clientPacket); - compound.putInt("GroupId", data.group.id); - compound.putFloat("GroupResistance", data.group.resistance); + writeElectricity(compound,clientPacket); } @Override @@ -264,9 +109,6 @@ public class CopycatCableBlockEntity extends CopycatBlockEntity implements IElec } // - data.group = new ElectricalGroup(compound.getInt("GroupId")); - data.group.resistance = compound.getFloat("GroupResistance"); - if (!clientPacket) - data.connectNextTick = true; + readElectricity(compound,clientPacket); } } diff --git a/src/main/java/com/drmangotea/tfmg/content/electricity/utilities/electric_motor/ElectricMotorBlockEntity.java b/src/main/java/com/drmangotea/tfmg/content/electricity/utilities/electric_motor/ElectricMotorBlockEntity.java index 9d5fbd37..af471cba 100644 --- a/src/main/java/com/drmangotea/tfmg/content/electricity/utilities/electric_motor/ElectricMotorBlockEntity.java +++ b/src/main/java/com/drmangotea/tfmg/content/electricity/utilities/electric_motor/ElectricMotorBlockEntity.java @@ -3,11 +3,14 @@ package com.drmangotea.tfmg.content.electricity.utilities.electric_motor; import com.drmangotea.tfmg.TFMG; import com.drmangotea.tfmg.config.MachineConfig; import com.drmangotea.tfmg.config.TFMGConfigs; +import com.drmangotea.tfmg.content.electricity.base.IElectric; import com.drmangotea.tfmg.content.electricity.base.KineticElectricBlockEntity; import com.mojang.blaze3d.vertex.PoseStack; +import com.simibubi.create.content.contraptions.bearing.WindmillBearingBlockEntity; import com.simibubi.create.content.kinetics.motor.KineticScrollValueBehaviour; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; import com.simibubi.create.foundation.blockEntity.behaviour.ValueBoxTransform; +import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollOptionBehaviour; import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollValueBehaviour; import com.simibubi.create.foundation.utility.CreateLang; import dev.engine_room.flywheel.lib.transform.TransformStack; @@ -28,120 +31,118 @@ import static com.simibubi.create.content.kinetics.base.DirectionalKineticBlock. public class ElectricMotorBlockEntity extends KineticElectricBlockEntity { - public static final int DEFAULT_SPEED = 64; - public static final int MAX_SPEED = 256; - protected ScrollValueBehaviour generatedSpeed; + public boolean delayedUpdate = false; - public float testSpeed = 0; + + + protected ScrollOptionBehaviour movementDirection; public ElectricMotorBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); - updateGeneratedRotation(); + } + @Override + public void onPlaced() { + super.onPlaced(); + for(IElectric member : getOrCreateElectricNetwork().members){ + if(member instanceof ElectricMotorBlockEntity be) + be.delayedUpdate = true; + + } + } + + + @Override public void tick() { super.tick(); + + + if(delayedUpdate){ - updateNextTick(); + updateGeneratedRotation(); delayedUpdate = false; } + } @Override public void addBehaviours(List behaviours) { super.addBehaviours(behaviours); - int max = MAX_SPEED; - generatedSpeed = new KineticScrollValueBehaviour(CreateLang.translateDirect("kinetics.creative_motor.rotation_speed"), - this, new MotorValueBox()); - generatedSpeed.between(-max, max); - generatedSpeed.value = DEFAULT_SPEED; - generatedSpeed.withCallback(i -> this.updateGeneratedRotation()); - behaviours.add(generatedSpeed); + movementDirection = new ScrollOptionBehaviour<>(WindmillBearingBlockEntity.RotationDirection.class, + CreateLang.translateDirect("contraptions.windmill.rotation_direction"), this, new MotorValueBox()); + + movementDirection.withCallback($ -> onDirectionChanged()); + behaviours.add(movementDirection); } + private void onDirectionChanged() { + updateNextTick(); + } + + + @Override public boolean hasElectricitySlot(Direction direction) { return direction == getBlockState().getValue(FACING).getOpposite() || (direction.getAxis().isHorizontal() && direction == Direction.DOWN); } - @Override - public void notifyNetworkAboutSpeedChange() { - super.notifyNetworkAboutSpeedChange(); - } - @Override - protected void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) { - super.write(compound,registries , clientPacket); - compound.putFloat("MotorSpeed",getSpeed()); - } - @Override - protected void read(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) { - super.read(compound,registries , clientPacket); - testSpeed = compound.getFloat("MotorSpeed"); - } @Override public void onNetworkChanged(int oldVoltage, int oldPower) { - if (oldPower != getPowerUsage() || oldVoltage != data.voltage) { - updateGeneratedRotation(); - } + //if (oldPower != getPowerUsage() || oldVoltage != data.voltage) { + delayedUpdate = true; + notifyUpdate(); + // } + } + + @Override + public void initialize() { + super.initialize(); + if (!hasSource() || getPowerUsage()>0) + updateNextTick(); } @Override public float getGeneratedSpeed() { - - MachineConfig machineConfig = TFMGConfigs.common().machines; - - //if(getPowerUsage() = machineConfig.electricMotorMinimumPower.get()){ - float speed = generatedSpeed.getValue() <0 ? -Math.min(Math.abs(data.getVoltage()/2),Math.abs(generatedSpeed.getValue())) : Math.min(Math.abs(data.getVoltage()/2),Math.abs(generatedSpeed.getValue())); - if(speed==0){ - return testSpeed; - } + int rotation = movementDirection.get() == WindmillBearingBlockEntity.RotationDirection.CLOCKWISE ? 1 : -1; + + float speed = Math.min(255,data.getVoltage()*.8f)*rotation; - testSpeed = 0; return speed; - //} - //return 0; } - @Override - public boolean canBeInGroups() { - return true; + public float calculateAddedStressCapacity() { + float speedModifier = getSpeed()/256; + + + return (int)(super.calculateAddedStressCapacity()*speedModifier); } - - + //@Override + //public boolean canBeInGroups() { + // return true; + //} @Override public float resistance() { return TFMGConfigs.common().machines.electricMotorInternalResistance.getF(); } - @Override - public int getPowerUsage() { - - if (Math.min(generatedSpeed.getValue(), data.getVoltage() / 2) == 0) - return super.getPowerUsage(); - - float speedModifier = (Math.min(Math.abs(generatedSpeed.getValue()), data.getVoltage()) / 256f) * 5; - - - return (int) ((float) super.getPowerUsage() * speedModifier); - } - class MotorValueBox extends ValueBoxTransform.Sided { @Override diff --git a/src/main/java/com/drmangotea/tfmg/content/electricity/utilities/electric_pump/ElectricPumpBlockEntity.java b/src/main/java/com/drmangotea/tfmg/content/electricity/utilities/electric_pump/ElectricPumpBlockEntity.java index 338742bf..f0da0d81 100644 --- a/src/main/java/com/drmangotea/tfmg/content/electricity/utilities/electric_pump/ElectricPumpBlockEntity.java +++ b/src/main/java/com/drmangotea/tfmg/content/electricity/utilities/electric_pump/ElectricPumpBlockEntity.java @@ -37,7 +37,7 @@ import static com.simibubi.create.content.kinetics.base.DirectionalKineticBlock. public class ElectricPumpBlockEntity extends PumpBlockEntity implements IElectric { public ElectricBlockValues data = new ElectricBlockValues(getPos()); - int powerPercentage = 100; + public ElectricPumpBlockEntity(BlockEntityType typeIn, BlockPos pos, BlockState state) { super(typeIn, pos, state); @@ -208,25 +208,12 @@ public class ElectricPumpBlockEntity extends PumpBlockEntity implements IElectri return level; } - @Override - public boolean destroyed() { - return data.destroyed; - } - @Override - public ElectricalNetwork getOrCreateElectricNetwork() { - if (level.getBlockEntity(BlockPos.of(data.electricalNetworkId)) instanceof IElectric) { - return TFMG.NETWORK_MANAGER.getOrCreateNetworkFor((IElectric) level.getBlockEntity(BlockPos.of(data.electricalNetworkId))); - } else { - ElectricNetworkManager.networks.get(getLevel()) - .remove(data.electricalNetworkId); - return TFMG.NETWORK_MANAGER.getOrCreateNetworkFor(this); - } - } @Override public void lazyTick() { super.lazyTick(); + lazyTickElectricity(); } @Override @@ -235,8 +222,6 @@ public class ElectricPumpBlockEntity extends PumpBlockEntity implements IElectri } - - @Override public float resistance() { return 100; @@ -244,112 +229,11 @@ public class ElectricPumpBlockEntity extends PumpBlockEntity implements IElectri - @Override - public int voltageGeneration() { - - int voltageGeneration = 0; - - for (Direction direction : Direction.values()) { - if (hasElectricitySlot(direction)) { - - if (level.getBlockEntity(getBlockPos().relative(direction)) instanceof VoltageAlteringBlockEntity be) - if (be.getData().getId() != getData().getId()) - if (be.getData().getVoltage() != 0) - if (be.hasElectricitySlot(direction)) { - voltageGeneration = Math.max(voltageGeneration, be.getOutputVoltage()); - data.getsOutsidePower = true; - } - } - } - - if (voltageGeneration == 0) - data.getsOutsidePower = false; - - return voltageGeneration; - } - - @Override - public int powerGeneration() { - - int powerGeneration = 0; - - for (Direction direction : Direction.values()) { - if (hasElectricitySlot(direction)) { - - if (level.getBlockEntity(getBlockPos().relative(direction)) instanceof VoltageAlteringBlockEntity be) { - if (be.getData().getId() != getData().getId()) - if (be.getData().getVoltage() != 0) - if (be.hasElectricitySlot(direction)) { - powerGeneration = Math.max(powerGeneration, be.getPowerUsage()) + 1; - } - } - } - } - - return powerGeneration; - } - - @Override - public int frequencyGeneration() { - return 0; - } - - @Override - public void updateNextTick() { - data.updateNextTick = true; - } - - @Override - public void updateNetwork() { - getOrCreateElectricNetwork().updateNetwork(); - if (level instanceof ServerLevel serverLevel) - CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition),new NetworkUpdatePacket(BlockPos.of(getPos()))); - sendData(); - } - @Override public void sendStuff() { sendData(); } - @Override - public void setVoltage(int newVoltage) { - - - if (canBeInGroups()) { - data.voltage = (int) (((float) resistance() / data.group.resistance) * (float) data.voltageSupply); - return; - } - data.voltage = newVoltage; - } - - @Override - public void setFrequency(int newFrequency) { - data.frequency = newFrequency; - } - - @Override - public void setNetworkResistance(int newUsage) { - data.networkResistance = newUsage; - } - - @Override - public int getNetworkResistance() { - return data.networkResistance; - } - - - - @Override - public void setNetwork(long network) { - this.data.electricalNetworkId = network; - if (network != getPos()) - ElectricNetworkManager.networks.get(getLevel()) - .remove(getPos()); - } - - - @Override public long getPos() { @@ -359,40 +243,13 @@ public class ElectricPumpBlockEntity extends PumpBlockEntity implements IElectri @Override public void remove() { super.remove(); - this.data.destroyed = true; - for (Direction d : Direction.values()) { - if (hasElectricitySlot(d)) - if (getLevelAccessor().getBlockEntity(BlockPos.of(getPos()).relative(d)) instanceof IElectric be && be.hasElectricitySlot(d.getOpposite())) { - ElectricNetworkManager.networks.get(getLevel()) - .remove(be.getPos()); - be.setNetwork(be.getPos()); - be.onPlaced(); - be.updateNextTick(); - } - } - if (data.electricalNetworkId != getPos()) - getOrCreateElectricNetwork().getMembers().remove(this); - - if (data.electricalNetworkId == getPos()) - ElectricNetworkManager.networks.get(getLevel()) - .remove(getData().getId()); + onRemoved(); } @Override public void tick() { super.tick(); - if (data.connectNextTick) { - onPlaced(); - data.connectNextTick = false; - } - if (data.updateNextTick) { - updateNetwork(); - data.updateNextTick = false; - } - if (data.setVoltageNextTick) { - setVoltage(data.voltageSupply); - data.setVoltageNextTick = false; - } + tickElectricity(); } @@ -400,17 +257,13 @@ public class ElectricPumpBlockEntity extends PumpBlockEntity implements IElectri protected void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) { super.write(compound,registries , clientPacket); - compound.putInt("GroupId", data.group.id); - compound.putFloat("GroupResistance", data.group.resistance); + writeElectricity(compound,clientPacket); } @Override protected void read(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) { super.read(compound,registries , clientPacket); - data.group = new ElectricalGroup(compound.getInt("GroupId")); - data.group.resistance = compound.getFloat("GroupResistance"); - if (!clientPacket) - data.connectNextTick = true; + readElectricity(compound,clientPacket); } /// ////////////////