electricity optimization
This commit is contained in:
44
README.md
Normal file
44
README.md
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<div align="center">
|
||||||
|
<img src="https://cdn.modrinth.com/data/USgVjXsk/a8150331e2257d66e03e09478f17e121fcd3fdea_96.webp">
|
||||||
|
<h1>Create: The Factory Must Grow</h1>
|
||||||
|
<a href="https://www.curseforge.com/minecraft/mc-mods/create-industry"><picture><source srcset="https://img.shields.io/badge/CurseForge-202830?style=for-the-badge&logo=curseforge" media="(prefers-color-scheme: dark)"><img src="https://img.shields.io/badge/CurseForge-white?style=for-the-badge&logo=curseforge" alt="CurseForge"></picture></a>
|
||||||
|
<a href="https://modrinth.com/mod/create-tfmg"><picture><source srcset="https://img.shields.io/badge/Modrinth-202830?style=for-the-badge&logo=modrinth" media="(prefers-color-scheme: dark)"><img src="https://img.shields.io/badge/Modrinth-white?style=for-the-badge&logo=modrinth" alt="Modrinth"></picture></a>
|
||||||
|
<a href="https://discord.gg/HCRF9PYdSy"><picture><source srcset="https://img.shields.io/badge/Discord-202830?style=for-the-badge&logo=discord" media="(prefers-color-scheme: dark)"><img src="https://img.shields.io/badge/Discord-white?style=for-the-badge&logo=discord" alt="Discord"></picture></a>
|
||||||
|
<br>
|
||||||
|
<a>Heavy Engineering & Oil For The Create Mod</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* Large Distilleries
|
||||||
|
* Realistic Electricity
|
||||||
|
* Steel Mills
|
||||||
|
* Concrete
|
||||||
|
* Electrolyzers
|
||||||
|
* Steel
|
||||||
|
* Aluminum
|
||||||
|
* Cast Iron
|
||||||
|
* Lead
|
||||||
|
* Sulfur
|
||||||
|
* OIL!!!
|
||||||
|
* Quad Potato Cannon
|
||||||
|
* Flamethrowers
|
||||||
|
* And more..
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
@@ -25,7 +25,6 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
|
|||||||
public ElectricBlockValues data = new ElectricBlockValues(getPos());
|
public ElectricBlockValues data = new ElectricBlockValues(getPos());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ElectricBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
public ElectricBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||||
super(type, pos, state);
|
super(type, pos, state);
|
||||||
data.connectNextTick = true;
|
data.connectNextTick = true;
|
||||||
@@ -34,7 +33,6 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addBehaviours(List<BlockEntityBehaviour> behaviours) {
|
public void addBehaviours(List<BlockEntityBehaviour> behaviours) {
|
||||||
}
|
}
|
||||||
@@ -44,32 +42,10 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
|
|||||||
return level;
|
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
|
@Override
|
||||||
public void lazyTick() {
|
public void lazyTick() {
|
||||||
super.lazyTick();
|
super.lazyTick();
|
||||||
if (data.failTimer >= 4) {
|
lazyTickElectricity();
|
||||||
this.blockFail();
|
|
||||||
data.failTimer = 0;
|
|
||||||
sendStuff();
|
|
||||||
} else if ((data.voltage > getMaxVoltage() && getMaxVoltage() > 0) || (getCurrent() > getMaxCurrent()&&getMaxCurrent()>0)) {
|
|
||||||
data.failTimer++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
public void sendStuff() {
|
public void sendStuff() {
|
||||||
sendData();
|
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
|
@Override
|
||||||
@@ -209,67 +69,28 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
super.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
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
if (data.checkForLoopsNextTick) {
|
tickElectricity();
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
|
protected void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
|
||||||
super.write(compound,registries , clientPacket);
|
super.write(compound,registries , clientPacket);
|
||||||
|
writeElectricity(compound,clientPacket);
|
||||||
|
|
||||||
compound.putInt("GroupId", data.group.id);
|
|
||||||
compound.putFloat("GroupResistance", data.group.resistance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void read(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
|
protected void read(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
|
||||||
super.read(compound,registries , clientPacket);
|
super.read(compound,registries , clientPacket);
|
||||||
data.group = new ElectricalGroup(compound.getInt("GroupId"));
|
readElectricity(compound,clientPacket);
|
||||||
data.group.resistance = compound.getFloat("GroupResistance");
|
|
||||||
if (!clientPacket)
|
|
||||||
data.connectNextTick = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import net.createmod.catnip.theme.Color;
|
|||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.core.HolderLookup;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
@@ -26,9 +28,19 @@ public interface IElectric {
|
|||||||
|
|
||||||
LevelAccessor getLevelAccessor();
|
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) {
|
default boolean hasElectricitySlot(Direction direction) {
|
||||||
return true;
|
return true;
|
||||||
@@ -43,35 +55,82 @@ public interface IElectric {
|
|||||||
getData().electricalNetworkId = getPos();
|
getData().electricalNetworkId = getPos();
|
||||||
network.add(this);
|
network.add(this);
|
||||||
|
|
||||||
BlockPos pos = BlockPos.of(getPos());
|
|
||||||
getData().checkForLoopsNextTick = true;
|
getData().checkForLoopsNextTick = true;
|
||||||
getOrCreateElectricNetwork().checkForLoops(BlockPos.of(getPos()));
|
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();
|
updateNextTick();
|
||||||
|
|
||||||
onConnected();
|
onConnected();
|
||||||
sendStuff();
|
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() {
|
default int getMaxVoltage() {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -106,6 +165,10 @@ public interface IElectric {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default BlockPos getBlockPos(){
|
||||||
|
return BlockPos.of(getPos());
|
||||||
|
}
|
||||||
|
|
||||||
default void updateUnpowered(List<BlockPos> alreadyChecked) {
|
default void updateUnpowered(List<BlockPos> alreadyChecked) {
|
||||||
alreadyChecked.add(BlockPos.of(getPos()));
|
alreadyChecked.add(BlockPos.of(getPos()));
|
||||||
updateNextTick();
|
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() {
|
default int getMaxAmps() {
|
||||||
return (int) getCurrent();
|
return (int) getCurrent();
|
||||||
@@ -307,20 +424,44 @@ public interface IElectric {
|
|||||||
return current;
|
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 sendStuff();
|
||||||
|
|
||||||
void setVoltage(int newVoltage);
|
|
||||||
|
|
||||||
void setFrequency(int newFrequency);
|
default void setVoltage(int newVoltage) {
|
||||||
|
|
||||||
void setNetworkResistance(int newUsage);
|
|
||||||
|
|
||||||
|
|
||||||
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() {
|
default boolean canBeInGroups() {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -26,10 +26,6 @@ import java.util.List;
|
|||||||
public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity implements IElectric, IHaveGoggleInformation, IHaveHoveringInformation {
|
public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity implements IElectric, IHaveGoggleInformation, IHaveHoveringInformation {
|
||||||
|
|
||||||
public ElectricBlockValues data = new ElectricBlockValues(getPos());
|
public ElectricBlockValues data = new ElectricBlockValues(getPos());
|
||||||
int powerPercentage = 100;
|
|
||||||
|
|
||||||
int timer = 0;
|
|
||||||
|
|
||||||
|
|
||||||
public KineticElectricBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
public KineticElectricBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||||
super(type, pos, state);
|
super(type, pos, state);
|
||||||
@@ -39,42 +35,16 @@ public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity imp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addBehaviours(List<BlockEntityBehaviour> behaviours) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LevelAccessor getLevelAccessor() {
|
public LevelAccessor getLevelAccessor() {
|
||||||
return level;
|
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
|
@Override
|
||||||
public void lazyTick() {
|
public void lazyTick() {
|
||||||
super.lazyTick();
|
super.lazyTick();
|
||||||
if (data.failTimer >= 4) {
|
lazyTickElectricity();
|
||||||
this.blockFail();
|
|
||||||
data.failTimer = 0;
|
|
||||||
sendStuff();
|
|
||||||
} else if ((data.voltage > getMaxVoltage() && getMaxVoltage() > 0) || (getCurrent() > getMaxCurrent() && getMaxCurrent() > 0)) {
|
|
||||||
data.failTimer++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
public void sendStuff() {
|
public void sendStuff() {
|
||||||
sendData();
|
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
|
@Override
|
||||||
@@ -210,68 +70,26 @@ public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity imp
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
super.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
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
if (data.checkForLoopsNextTick) {
|
tickElectricity();
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
|
protected void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
|
||||||
super.write(compound,registries , clientPacket);
|
super.write(compound,registries , clientPacket);
|
||||||
|
writeElectricity(compound,clientPacket);
|
||||||
compound.putInt("GroupId", data.group.id);
|
|
||||||
compound.putFloat("GroupResistance", data.group.resistance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void read(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
|
protected void read(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
|
||||||
super.read(compound,registries , clientPacket);
|
super.read(compound,registries , clientPacket);
|
||||||
data.group = new ElectricalGroup(compound.getInt("GroupId"));
|
readElectricity(compound,clientPacket);
|
||||||
data.group.resistance = compound.getFloat("GroupResistance");
|
|
||||||
if (!clientPacket)
|
|
||||||
data.connectNextTick = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -281,7 +99,7 @@ public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity imp
|
|||||||
|
|
||||||
if (this instanceof RegularEngineBlockEntity)
|
if (this instanceof RegularEngineBlockEntity)
|
||||||
notifyNetworkAboutSpeedChange();
|
notifyNetworkAboutSpeedChange();
|
||||||
timer = 0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ public class CopycatCableBlockEntity extends CopycatBlockEntity implements IElec
|
|||||||
|
|
||||||
public ElectricBlockValues data = new ElectricBlockValues(getPos());
|
public ElectricBlockValues data = new ElectricBlockValues(getPos());
|
||||||
|
|
||||||
int powerPercentage = 100;
|
|
||||||
boolean setNextTick = true;
|
|
||||||
public CopycatCableBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
public CopycatCableBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||||
super(type, pos, state);
|
super(type, pos, state);
|
||||||
data.connectNextTick = true;
|
data.connectNextTick = true;
|
||||||
@@ -40,38 +38,19 @@ public class CopycatCableBlockEntity extends CopycatBlockEntity implements IElec
|
|||||||
data.group = new ElectricalGroup(-1);
|
data.group = new ElectricalGroup(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public boolean hasCustomMaterial() {
|
|
||||||
return !AllBlocks.COPYCAT_BASE.has(getMaterial());
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void addBehaviours(List<BlockEntityBehaviour> behaviours) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LevelAccessor getLevelAccessor() {
|
public LevelAccessor getLevelAccessor() {
|
||||||
return level;
|
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
|
@Override
|
||||||
public void lazyTick() {
|
public void lazyTick() {
|
||||||
super.lazyTick();
|
super.lazyTick();
|
||||||
|
lazyTickElectricity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
public void sendStuff() {
|
public void sendStuff() {
|
||||||
sendData();
|
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
|
@Override
|
||||||
public long getPos() {
|
public long getPos() {
|
||||||
@@ -199,52 +76,20 @@ public class CopycatCableBlockEntity extends CopycatBlockEntity implements IElec
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
super.remove();
|
super.remove();
|
||||||
this.data.destroyed = true;
|
onRemoved();
|
||||||
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
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
if (data.connectNextTick) {
|
tickElectricity();
|
||||||
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;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
|
protected void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
|
||||||
super.write(compound,registries , clientPacket);
|
super.write(compound,registries , clientPacket);
|
||||||
|
|
||||||
compound.putInt("GroupId", data.group.id);
|
writeElectricity(compound,clientPacket);
|
||||||
compound.putFloat("GroupResistance", data.group.resistance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -264,9 +109,6 @@ public class CopycatCableBlockEntity extends CopycatBlockEntity implements IElec
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
data.group = new ElectricalGroup(compound.getInt("GroupId"));
|
readElectricity(compound,clientPacket);
|
||||||
data.group.resistance = compound.getFloat("GroupResistance");
|
|
||||||
if (!clientPacket)
|
|
||||||
data.connectNextTick = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,14 @@ package com.drmangotea.tfmg.content.electricity.utilities.electric_motor;
|
|||||||
import com.drmangotea.tfmg.TFMG;
|
import com.drmangotea.tfmg.TFMG;
|
||||||
import com.drmangotea.tfmg.config.MachineConfig;
|
import com.drmangotea.tfmg.config.MachineConfig;
|
||||||
import com.drmangotea.tfmg.config.TFMGConfigs;
|
import com.drmangotea.tfmg.config.TFMGConfigs;
|
||||||
|
import com.drmangotea.tfmg.content.electricity.base.IElectric;
|
||||||
import com.drmangotea.tfmg.content.electricity.base.KineticElectricBlockEntity;
|
import com.drmangotea.tfmg.content.electricity.base.KineticElectricBlockEntity;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
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.content.kinetics.motor.KineticScrollValueBehaviour;
|
||||||
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
|
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
|
||||||
import com.simibubi.create.foundation.blockEntity.behaviour.ValueBoxTransform;
|
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.blockEntity.behaviour.scrollValue.ScrollValueBehaviour;
|
||||||
import com.simibubi.create.foundation.utility.CreateLang;
|
import com.simibubi.create.foundation.utility.CreateLang;
|
||||||
import dev.engine_room.flywheel.lib.transform.TransformStack;
|
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 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 boolean delayedUpdate = false;
|
||||||
|
|
||||||
public float testSpeed = 0;
|
|
||||||
|
|
||||||
|
protected ScrollOptionBehaviour<WindmillBearingBlockEntity.RotationDirection> movementDirection;
|
||||||
|
|
||||||
public ElectricMotorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
public ElectricMotorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||||
super(type, pos, 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
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(delayedUpdate){
|
if(delayedUpdate){
|
||||||
updateNextTick();
|
updateGeneratedRotation();
|
||||||
delayedUpdate = false;
|
delayedUpdate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addBehaviours(List<BlockEntityBehaviour> behaviours) {
|
public void addBehaviours(List<BlockEntityBehaviour> behaviours) {
|
||||||
super.addBehaviours(behaviours);
|
super.addBehaviours(behaviours);
|
||||||
int max = MAX_SPEED;
|
movementDirection = new ScrollOptionBehaviour<>(WindmillBearingBlockEntity.RotationDirection.class,
|
||||||
generatedSpeed = new KineticScrollValueBehaviour(CreateLang.translateDirect("kinetics.creative_motor.rotation_speed"),
|
CreateLang.translateDirect("contraptions.windmill.rotation_direction"), this, new MotorValueBox());
|
||||||
this, new MotorValueBox());
|
|
||||||
generatedSpeed.between(-max, max);
|
movementDirection.withCallback($ -> onDirectionChanged());
|
||||||
generatedSpeed.value = DEFAULT_SPEED;
|
behaviours.add(movementDirection);
|
||||||
generatedSpeed.withCallback(i -> this.updateGeneratedRotation());
|
|
||||||
behaviours.add(generatedSpeed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onDirectionChanged() {
|
||||||
|
updateNextTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasElectricitySlot(Direction direction) {
|
public boolean hasElectricitySlot(Direction direction) {
|
||||||
return direction == getBlockState().getValue(FACING).getOpposite() || (direction.getAxis().isHorizontal() && direction == Direction.DOWN);
|
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
|
@Override
|
||||||
public void onNetworkChanged(int oldVoltage, int oldPower) {
|
public void onNetworkChanged(int oldVoltage, int oldPower) {
|
||||||
if (oldPower != getPowerUsage() || oldVoltage != data.voltage) {
|
//if (oldPower != getPowerUsage() || oldVoltage != data.voltage) {
|
||||||
updateGeneratedRotation();
|
delayedUpdate = true;
|
||||||
}
|
notifyUpdate();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
super.initialize();
|
||||||
|
if (!hasSource() || getPowerUsage()>0)
|
||||||
|
updateNextTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getGeneratedSpeed() {
|
public float getGeneratedSpeed() {
|
||||||
|
if(networkUndersupplied())
|
||||||
MachineConfig machineConfig = TFMGConfigs.common().machines;
|
return 0;
|
||||||
|
|
||||||
//if(getPowerUsage() <machineConfig.electricMotorMinimumPower.get())
|
|
||||||
// return 0;
|
|
||||||
if (!canWork())
|
if (!canWork())
|
||||||
return 0;
|
return 0;
|
||||||
//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){
|
int rotation = movementDirection.get() == WindmillBearingBlockEntity.RotationDirection.CLOCKWISE ? 1 : -1;
|
||||||
return testSpeed;
|
|
||||||
}
|
float speed = Math.min(255,data.getVoltage()*.8f)*rotation;
|
||||||
|
|
||||||
testSpeed = 0;
|
|
||||||
return speed;
|
return speed;
|
||||||
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
//return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canBeInGroups() {
|
public float calculateAddedStressCapacity() {
|
||||||
return true;
|
float speedModifier = getSpeed()/256;
|
||||||
|
|
||||||
|
|
||||||
|
return (int)(super.calculateAddedStressCapacity()*speedModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@Override
|
||||||
|
//public boolean canBeInGroups() {
|
||||||
|
// return true;
|
||||||
|
//}
|
||||||
@Override
|
@Override
|
||||||
public float resistance() {
|
public float resistance() {
|
||||||
|
|
||||||
return TFMGConfigs.common().machines.electricMotorInternalResistance.getF();
|
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 {
|
class MotorValueBox extends ValueBoxTransform.Sided {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import static com.simibubi.create.content.kinetics.base.DirectionalKineticBlock.
|
|||||||
public class ElectricPumpBlockEntity extends PumpBlockEntity implements IElectric {
|
public class ElectricPumpBlockEntity extends PumpBlockEntity implements IElectric {
|
||||||
|
|
||||||
public ElectricBlockValues data = new ElectricBlockValues(getPos());
|
public ElectricBlockValues data = new ElectricBlockValues(getPos());
|
||||||
int powerPercentage = 100;
|
|
||||||
|
|
||||||
public ElectricPumpBlockEntity(BlockEntityType<?> typeIn, BlockPos pos, BlockState state) {
|
public ElectricPumpBlockEntity(BlockEntityType<?> typeIn, BlockPos pos, BlockState state) {
|
||||||
super(typeIn, pos, state);
|
super(typeIn, pos, state);
|
||||||
@@ -208,25 +208,12 @@ public class ElectricPumpBlockEntity extends PumpBlockEntity implements IElectri
|
|||||||
return level;
|
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
|
@Override
|
||||||
public void lazyTick() {
|
public void lazyTick() {
|
||||||
super.lazyTick();
|
super.lazyTick();
|
||||||
|
lazyTickElectricity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -235,8 +222,6 @@ public class ElectricPumpBlockEntity extends PumpBlockEntity implements IElectri
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float resistance() {
|
public float resistance() {
|
||||||
return 100;
|
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
|
@Override
|
||||||
public void sendStuff() {
|
public void sendStuff() {
|
||||||
sendData();
|
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
|
@Override
|
||||||
public long getPos() {
|
public long getPos() {
|
||||||
@@ -359,40 +243,13 @@ public class ElectricPumpBlockEntity extends PumpBlockEntity implements IElectri
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
super.remove();
|
super.remove();
|
||||||
this.data.destroyed = true;
|
onRemoved();
|
||||||
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
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
if (data.connectNextTick) {
|
tickElectricity();
|
||||||
onPlaced();
|
|
||||||
data.connectNextTick = false;
|
|
||||||
}
|
|
||||||
if (data.updateNextTick) {
|
|
||||||
updateNetwork();
|
|
||||||
data.updateNextTick = false;
|
|
||||||
}
|
|
||||||
if (data.setVoltageNextTick) {
|
|
||||||
setVoltage(data.voltageSupply);
|
|
||||||
data.setVoltageNextTick = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,17 +257,13 @@ public class ElectricPumpBlockEntity extends PumpBlockEntity implements IElectri
|
|||||||
protected void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
|
protected void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
|
||||||
super.write(compound,registries , clientPacket);
|
super.write(compound,registries , clientPacket);
|
||||||
|
|
||||||
compound.putInt("GroupId", data.group.id);
|
writeElectricity(compound,clientPacket);
|
||||||
compound.putFloat("GroupResistance", data.group.resistance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void read(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
|
protected void read(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
|
||||||
super.read(compound,registries , clientPacket);
|
super.read(compound,registries , clientPacket);
|
||||||
data.group = new ElectricalGroup(compound.getInt("GroupId"));
|
readElectricity(compound,clientPacket);
|
||||||
data.group.resistance = compound.getFloat("GroupResistance");
|
|
||||||
if (!clientPacket)
|
|
||||||
data.connectNextTick = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ////////////////
|
/// ////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user