more stuff

This commit is contained in:
DrMangoTea
2025-05-12 20:55:57 +02:00
parent 2b1120cf38
commit be710fa76b
35 changed files with 18209 additions and 8335 deletions

View File

@@ -13,13 +13,14 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.network.PacketDistributor;
import java.util.ArrayList;
import java.util.List;
public class ElectricBlockEntity extends SmartBlockEntity implements IElectric, IHaveHoveringInformation {
public ElectricBlockValues data = new ElectricBlockValues(getPos());
int powerPercentage = 100;
public ElectricBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
@@ -58,6 +59,7 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
@Override
public void lazyTick() {
super.lazyTick();
// updateNetwork();
//if (data.failTimer >= 4) {
// this.blockFail();
// data.failTimer = 0;
@@ -74,10 +76,7 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
}
@Override
public int getPowerPercentage() {
return powerPercentage;
}
@Override
public float resistance() {
@@ -108,6 +107,8 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
return voltageGeneration;
}
@Override
public int powerGeneration() {
@@ -118,11 +119,14 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
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;
}
}
}
}
@@ -183,14 +187,6 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
return data.networkResistance;
}
@Override
public void setWattage(int newWattage) {
}
@Override
public void setPowerPercentage(int percentage) {
powerPercentage = percentage;
}
@Override
public void setNetwork(long network) {
@@ -236,6 +232,10 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
@Override
public void tick() {
super.tick();
if (data.checkForLoopsNextTick) {
getOrCreateElectricNetwork().checkForLoops(getBlockPos());
data.checkForLoopsNextTick = false;
}
if (data.connectNextTick) {
onPlaced();
data.connectNextTick = false;
@@ -244,6 +244,11 @@ public class ElectricBlockEntity extends SmartBlockEntity implements IElectric,
updateNetwork();
data.updateNextTick = false;
}
if (data.updatePowerNextTick) {
updateUnpowered(new ArrayList<>());
data.updatePowerNextTick = false;
}
if (data.setVoltageNextTick) {
setVoltage(data.voltageSupply);
data.setVoltageNextTick = false;

View File

@@ -6,6 +6,8 @@ public class ElectricBlockValues {
public long electricalNetworkId;
public boolean destroyed = false;
public boolean connectNextTick = false;
public boolean checkForLoopsNextTick = false;
public boolean updatePowerNextTick = false;
public boolean updateNextTick = false;
public boolean getsOutsidePower = false;
public int networkResistance = 0;

View File

@@ -1,13 +1,14 @@
package com.drmangotea.tfmg.content.electricity.base;
import com.drmangotea.tfmg.TFMG;
import com.drmangotea.tfmg.content.electricity.utilities.diode.ElectricDiodeBlockEntity;
import com.drmangotea.tfmg.content.electricity.utilities.electric_motor.ElectricMotorBlockEntity;
import com.drmangotea.tfmg.content.electricity.utilities.transformer.TransformerBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.Blocks;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public class ElectricalNetwork {
@@ -17,6 +18,7 @@ public class ElectricalNetwork {
public List<IElectric> members = new ArrayList<>();
public long id;
public long getId() {
@@ -53,47 +55,61 @@ public class ElectricalNetwork {
powerGeneration += member.powerGeneration();
if (member.canBeInGroups())
groups.put(groupId, groups.containsKey(groupId) ? groups.get(groupId) + member.resistance() : member.resistance());
}
int powerPercentage = resistance > 0 ? (int) (Math.min(((float) power / (float) resistance * 100f), 100)) : 100;
List<IElectric> list = new ArrayList<>(members);
if(!members.isEmpty()) {
float powerUsage = members.get(0).getNetworkPowerUsage();
for (IElectric member : list) {
for (IElectric member : list) {
int oldVoltage = member.getData().getVoltage();
int oldPower = member.getPowerUsage();
member.getData().voltageSupply = maxVoltage;
member.setVoltage(maxVoltage);
member.getData().setVoltageNextTick = true;
int oldVoltage = member.getData().getVoltage();
int oldPower = member.getPowerUsage();
member.getData().voltageSupply = maxVoltage;
member.setVoltage(maxVoltage);
member.getData().setVoltageNextTick = true;
member.getData().networkPowerGeneration = powerGeneration;
member.setWattage(power);
member.setFrequency(frequency);
member.setNetworkResistance(resistance);
member.onNetworkChanged(oldVoltage, oldPower);
member.setPowerPercentage(powerPercentage);
member.getData().networkPowerGeneration = powerGeneration;
member.setFrequency(frequency);
member.setNetworkResistance(resistance);
member.onNetworkChanged(oldVoltage, oldPower);
if (groups.containsKey(member.getData().group.id))
member.getData().group.resistance = groups.get(member.getData().group.id);
if (groups.containsKey(member.getData().group.id))
member.getData().group.resistance = groups.get(member.getData().group.id);
}
}
for (IElectric member : members) {
member.getData().highestCurrent = getCableCurrent(member);
member.updateNearbyNetworks(member);
if(member instanceof ElectricDiodeBlockEntity be) {
be.updateInFront();
}
if(member instanceof TransformerBlockEntity be) {
be.updateInFront();
}
// if (member instanceof KineticElectricBlockEntity be) {
// be.updateGeneratedRotation();
// }
}
handleInsufficientPower();
}
public void handleInsufficientPower(){
if (!members.isEmpty())
if (members.get(0).getNetworkPowerUsage() > members.get(0).getNetworkPowerGeneration()) {
// members.get(0).updateUnpowered(new ArrayList<>());
for (IElectric member : members) {
member.getData().notEnoughtPower = true;
if (member instanceof ElectricMotorBlockEntity be) {
be.updateGeneratedRotation();
be.preventSpeedUpdate = 20;
}
if (member instanceof ElectricDiodeBlockEntity be)
be.updateInFront=true;
@@ -103,6 +119,7 @@ public class ElectricalNetwork {
}
}
public static float getCableCurrent(IElectric be) {
float current = 0;
@@ -123,6 +140,38 @@ public class ElectricalNetwork {
return current;
}
public void checkForLoops(BlockPos pos ){
members.forEach(member->{
if(member instanceof VoltageAlteringBlockEntity be){
if(be.getControlledBlock() !=null){
List<ElectricalNetwork> list = new ArrayList<>();
list.add(this);
be.getControlledBlock().getOrCreateElectricNetwork().checkForLoops(list, pos);
}
}});
}
public void checkForLoops(List<ElectricalNetwork> network, BlockPos pos){
if(network.contains(this)) {
if(!members.isEmpty())
members.get(0).getLevelAccessor().destroyBlock(pos,false);
return;
}
network.add(this);
members.forEach(member->{
if(member instanceof VoltageAlteringBlockEntity be){
if(be.getControlledBlock() !=null){
be.getControlledBlock().getOrCreateElectricNetwork().checkForLoops(network, pos);
}
}});
}
public List<IElectric> getMembers() {
return members;
}

View File

@@ -2,8 +2,9 @@ package com.drmangotea.tfmg.content.electricity.base;
import com.drmangotea.tfmg.TFMG;
import com.drmangotea.tfmg.base.TFMGUtils;
import com.drmangotea.tfmg.content.electricity.connection.cables.CableConnection;
import com.drmangotea.tfmg.content.electricity.connection.cables.CableConnectorBlockEntity;
import com.drmangotea.tfmg.registry.TFMGPackets;
import com.simibubi.create.foundation.utility.CreateLang;
import net.createmod.catnip.theme.Color;
import net.minecraft.ChatFormatting;
@@ -11,6 +12,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.network.PacketDistributor;
import java.util.ArrayList;
@@ -40,26 +42,28 @@ public interface IElectric {
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 (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);
// for(IElectric member : be.getOrCreateElectricNetwork().members){
// network.add(member);
// member.setNetwork(this.getData().electricalNetworkId);
//
// }
// }
//
// }
// }
// }
// }
// }
// }
// }
// }
updateNextTick();
onConnected();
@@ -100,18 +104,48 @@ public interface IElectric {
}
default void updateUnpowered(List<BlockPos> alreadyChecked) {
alreadyChecked.add(BlockPos.of(getPos()));
updateNextTick();
if(this instanceof CableConnectorBlockEntity connectorBE){
for(CableConnection connection : connectorBE.connections){
if(getLevelAccessor().getBlockEntity(connection.blockPos1) instanceof CableConnectorBlockEntity be2 &&!alreadyChecked.contains(BlockPos.of(be2.getPos()))
){
// this.getLevelAccessor().setBlock(connection.blockPos1.above(2),Blocks.NETHER_BRICKS.defaultBlockState(),3);
be2.updateUnpowered(alreadyChecked);
}
}
}
for (Direction direction : Direction.values()) {
if(getLevelAccessor().getBlockEntity(BlockPos.of(getPos()).relative(direction)) instanceof IElectric be&&!alreadyChecked.contains(BlockPos.of(be.getPos()))){
be.updateUnpowered(alreadyChecked);
// be.getLevelAccessor().setBlock(BlockPos.of(getPos()).above(2),Blocks.NETHERRACK.defaultBlockState(),3);
}
}
}
default boolean makeMultimeterTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
CreateLang.translate("multimeter.header")
.style(ChatFormatting.WHITE)
.forGoggles(tooltip);
if(getData().notEnoughtPower) {
if (getData().notEnoughtPower) {
CreateLang.text("NOT ENOUGHT POWER")
.color(Color.RED)
.forGoggles(tooltip, 1);
// return true;
// return true;
}
//CreateLang.text("Network Power ")
// .color(Color.RED)
// .forGoggles(tooltip, 1);
if (voltageGeneration() > 0) {
CreateLang.translate("multimeter.power_generated")
.add(Component.literal(TFMGUtils.formatUnits(powerGeneration(), "W")))
@@ -138,7 +172,7 @@ public interface IElectric {
CreateLang.text(" P = " + TFMGUtils.formatUnits(getPowerUsage(), "W"))
.color(0xcc4b74)
.forGoggles(tooltip, 1);
if(getData().group.id!=-1){
if (getData().group.id != -1) {
CreateLang.text("----------------------------")
.style(ChatFormatting.WHITE)
.forGoggles(tooltip);
@@ -148,7 +182,7 @@ public interface IElectric {
.forGoggles(tooltip, 1);
}
if(isPlayerSneaking) {
if (isPlayerSneaking) {
CreateLang.text("----------------------------")
.style(ChatFormatting.WHITE)
.forGoggles(tooltip);
@@ -166,22 +200,23 @@ public interface IElectric {
}
default void updateNearbyNetworks(IElectric member) {
if (member.getData().getsOutsidePower)
for (Direction direction : Direction.values()) {
if (member.getLevelAccessor().getBlockEntity(BlockPos.of(member.getPos()).relative(direction)) instanceof IElectric be && be.getData().getId() != be.getData().getId()) {
be.updateNextTick();
}
if (true)
return;
//if (member.getData().getsOutsidePower) {
for (Direction direction : Direction.values()) {
if (member.getLevelAccessor().getBlockEntity(BlockPos.of(member.getPos()).relative(direction)) instanceof IElectric be && be.getData().getId() != member.getData().getId()) {
TFMG.LOGGER.debug("SIGMA");
be.getLevelAccessor().setBlock(BlockPos.of(be.getPos()).above(3), Blocks.GOLD_BLOCK.defaultBlockState(), 3);
be.updateNextTick();
}
}
default boolean isCable() {
return false;
}
// }
}
ElectricBlockValues getData();
default boolean canWork(){
default boolean canWork() {
return !getData().notEnoughtPower;
}
@@ -205,10 +240,12 @@ public interface IElectric {
default int getNetworkPowerUsage() {
int power = 0;
for (IElectric member : getOrCreateElectricNetwork().members)
power += member.getPowerUsage();
return power;
}
default int getNetworkPowerGeneration() {
int power = 0;
for (IElectric member : getOrCreateElectricNetwork().members)
@@ -224,7 +261,7 @@ public interface IElectric {
if (getData().voltageSupply == 0)
return 0;
if((float) getData().networkPowerGeneration * (float) getNetworkResistance()==0)
if ((float) getData().networkPowerGeneration * (float) getNetworkResistance() == 0)
return 0;
return (float) powerGeneration() / (float) getData().networkPowerGeneration * (float) getNetworkResistance();
@@ -236,7 +273,6 @@ public interface IElectric {
return (float) powerGeneration() / (float) getData().networkPowerGeneration * getNetworkPowerUsage();
}
int getPowerPercentage();
float resistance();
@@ -281,9 +317,6 @@ public interface IElectric {
void setNetworkResistance(int newUsage);
void setWattage(int newWattage);
void setPowerPercentage(int percentage);
void setNetwork(long network);

View File

@@ -70,10 +70,6 @@ public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity imp
@Override
public int getPowerPercentage() {
return powerPercentage;
}
@Override
public float resistance() {
@@ -173,14 +169,7 @@ public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity imp
return data.networkResistance;
}
@Override
public void setWattage(int newWattage) {
}
@Override
public void setPowerPercentage(int percentage) {
powerPercentage = percentage;
}
@Override
public void setNetwork(long network) {
@@ -190,11 +179,6 @@ public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity imp
.remove(getPos());
}
public boolean networkUndersupplied(){
return getNetworkPowerUsage()>data.networkPowerGeneration;
}
@Override
public long getPos() {
return getBlockPos().asLong();
@@ -226,14 +210,6 @@ public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity imp
public void tick() {
super.tick();
//if(timer == 2){
// updateNextTick();
//}
//if(timer<=2){
// timer++;
//}
if(data.connectNextTick) {
onPlaced();
data.connectNextTick = false;
@@ -260,13 +236,20 @@ public class KineticElectricBlockEntity extends GeneratingKineticBlockEntity imp
}
@Override
protected void write(CompoundTag tag, boolean clientPacket) {
super.write(tag, clientPacket);
protected void write(CompoundTag compound, boolean clientPacket) {
super.write(compound, clientPacket);
compound.putInt("GroupId", data.group.id);
compound.putFloat("GroupResistance", data.group.resistance);
compound.putFloat("MotorSpeed", getSpeed());
}
@Override
protected void read(CompoundTag tag, boolean clientPacket) {
super.read(tag, clientPacket);
protected void read(CompoundTag compound, boolean clientPacket) {
super.read(compound, clientPacket);
data.group = new ElectricalGroup(compound.getInt("GroupId"));
data.group.resistance = compound.getFloat("GroupResistance");
setSpeed(compound.getFloat("MotorSpeed"));
if(!clientPacket)
data.connectNextTick = true;

View File

@@ -12,4 +12,6 @@ public abstract class VoltageAlteringBlockEntity extends ElectricBlockEntity{
public abstract int getOutputVoltage();
public abstract int getOutputPower();
public abstract IElectric getControlledBlock();
}

View File

@@ -3,6 +3,7 @@ package com.drmangotea.tfmg.content.electricity.configuration_wrench;
import com.drmangotea.tfmg.base.TFMGUtils;
import com.drmangotea.tfmg.content.electricity.base.IElectric;
import com.drmangotea.tfmg.content.electricity.base.KineticElectricBlockEntity;
import com.drmangotea.tfmg.content.electricity.utilities.electric_motor.ElectricMotorBlockEntity;
import com.drmangotea.tfmg.content.engines.base.AbstractEngineBlockEntity;
import net.createmod.catnip.gui.ScreenOpener;
import net.minecraft.core.BlockPos;
@@ -11,6 +12,7 @@ import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
@@ -43,6 +45,7 @@ public class ElectriciansWrenchItem extends Item {
return new InteractionResultHolder<>(InteractionResult.SUCCESS, itemStack);
}
@Override
public InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel();
@@ -50,14 +53,14 @@ public class ElectriciansWrenchItem extends Item {
if(!context.getPlayer().isShiftKeyDown()) {
if (level.getBlockEntity(pos) instanceof IElectric be && be.canBeInGroups()) {
be.getData().group.id = context.getItemInHand().getOrCreateTag().getInt("Number");
TFMGUtils.playSound(level, pos, SoundEvents.ITEM_PICKUP, SoundSource.BLOCKS, context.getPlayer());
if(be instanceof KineticElectricBlockEntity kineticBE)
kineticBE.updateGeneratedRotation();
be.updateNextTick();
be.sendStuff();
be.getData().group.id = context.getItemInHand().getOrCreateTag().getInt("Number");
TFMGUtils.playSound(level, pos, SoundEvents.ITEM_PICKUP, SoundSource.BLOCKS, context.getPlayer());
if(be instanceof ElectricMotorBlockEntity kineticBE)
kineticBE.delayedUpdate=true;
return InteractionResult.SUCCESS;
}
if (level.getBlockEntity(pos) instanceof AbstractEngineBlockEntity be ) {

View File

@@ -10,8 +10,5 @@ public class CableHubBlockEntity extends ElectricBlockEntity {
super(type, pos, state);
}
@Override
public boolean isCable() {
return true;
}
}

View File

@@ -71,7 +71,7 @@ public class CableConnectorBlockEntity extends ElectricBlockEntity implements IH
return;
for (CableConnection connection : connections) {
ItemEntity itemToDrop = new ItemEntity(level, getBlockPos().getX() + 0.5f, getBlockPos().getY() + 0.5f, getBlockPos().getZ() + 0.5f, new ItemStack(connection.type.wire.get(), (int) (connection.getLength())));
ItemEntity itemToDrop = new ItemEntity(level, getBlockPos().getX() + 0.5f, getBlockPos().getY() + 0.5f, getBlockPos().getZ() + 0.5f, new ItemStack(connection.type.wire.get(), (int) (connection.getLength()/8)));
if (itemToDrop.getItem().getCount() > 0) {
level.addFreshEntity(itemToDrop);
}

View File

@@ -75,11 +75,6 @@ public class CopycatCableBlockEntity extends CopycatBlockEntity implements IElec
}
@Override
public int getPowerPercentage() {
return powerPercentage;
}
@Override
public float resistance() {
return 0;
@@ -176,16 +171,7 @@ public class CopycatCableBlockEntity extends CopycatBlockEntity implements IElec
public int getNetworkResistance() {
return data.networkResistance;
}
@Override
public void setWattage(int newWattage) {
}
@Override
public void setPowerPercentage(int percentage) {
powerPercentage = percentage;
}
@Override
public void setNetwork(long network) {
this.data.electricalNetworkId = network;

View File

@@ -27,6 +27,7 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;
@@ -82,23 +83,23 @@ public class DebugCinderBlockItem extends Item {
return InteractionResult.SUCCESS;
}
if (level.getBlockEntity(pos) instanceof CableConnectorBlockEntity be) {
if (context.getPlayer().isShiftKeyDown()) {
TFMG.LOGGER.debug("///////////////////////////////");
for (CableConnection connection : be.connections) {
TFMG.LOGGER.debug("Primary Pos " + connection.blockPos1.getX() + " " + connection.blockPos1.getY() + " " + connection.blockPos1.getZ());
}
TFMG.LOGGER.debug("///////////////////////////////");
return InteractionResult.SUCCESS;
}
TFMG.LOGGER.debug("///////////////////////////////");
TFMG.LOGGER.debug("Connector Count " + be.getConnectedWires().size());
TFMG.LOGGER.debug("Wire Count " + be.connections.size());
TFMG.LOGGER.debug("Member Count " + be.getOrCreateElectricNetwork().members.size());
TFMG.LOGGER.debug("Id " + "X " + BlockPos.of(be.getData().electricalNetworkId).getX() + " Y " + BlockPos.of(be.getData().electricalNetworkId).getY() + " Z " + BlockPos.of(be.getData().electricalNetworkId).getZ());
TFMG.LOGGER.debug("///////////////////////////////");
return InteractionResult.SUCCESS;
}
// if (level.getBlockEntity(pos) instanceof CableConnectorBlockEntity be) {
// if (context.getPlayer().isShiftKeyDown()) {
// TFMG.LOGGER.debug("///////////////////////////////");
// for (CableConnection connection : be.connections) {
// TFMG.LOGGER.debug("Primary Pos " + connection.blockPos1.getX() + " " + connection.blockPos1.getY() + " " + connection.blockPos1.getZ());
// }
// TFMG.LOGGER.debug("///////////////////////////////");
// return InteractionResult.SUCCESS;
// }
// TFMG.LOGGER.debug("///////////////////////////////");
// TFMG.LOGGER.debug("Connector Count " + be.getConnectedWires().size());
// TFMG.LOGGER.debug("Wire Count " + be.connections.size());
// TFMG.LOGGER.debug("Member Count " + be.getOrCreateElectricNetwork().members.size());
// TFMG.LOGGER.debug("Id " + "X " + BlockPos.of(be.getData().electricalNetworkId).getX() + " Y " + BlockPos.of(be.getData().electricalNetworkId).getY() + " Z " + BlockPos.of(be.getData().electricalNetworkId).getZ());
// TFMG.LOGGER.debug("///////////////////////////////");
// return InteractionResult.SUCCESS;
// }
if (level.getBlockEntity(pos) instanceof IElectric be) {
// be.onPlaced();
@@ -112,8 +113,14 @@ public class DebugCinderBlockItem extends Item {
TFMG.LOGGER.debug("Higherst Current " + be.getData().highestCurrent);
TFMG.LOGGER.debug("Group " + be.getData().group.id);
TFMG.LOGGER.debug("///////////////////////////////");
for(IElectric member : be.getOrCreateElectricNetwork().members){
level.setBlock(BlockPos.of(member.getPos()).above(3), Blocks.GOLD_BLOCK.defaultBlockState(),3);
}
} else {
be.updateNextTick();
//be.updateNextTick();
be.getOrCreateElectricNetwork().checkForLoops(BlockPos.of(be.getPos()));
TFMGUtils.debugMessage(level, "Power " + be.getNetworkPowerUsage());
TFMGUtils.debugMessage(level, "Voltage " + be.getData().getVoltage());
@@ -158,6 +165,8 @@ public class DebugCinderBlockItem extends Item {
//be.getControllerBE().rpm = 0;
//be.getControllerBE().engineController = null;
//be.getControllerBE().updateGeneratedRotation();
be.updateGeneratedRotation();
TFMGUtils.debugMessage(level, "RPM "+be.getControllerBE().shift);
TFMGUtils.debugMessage(level, "RPM "+be.getControllerBE().rpm);
TFMGUtils.debugMessage(level, "SIGNAL "+be.getControllerBE().signal);
TFMGUtils.debugMessage(level, "HSIGNAL "+be.getControllerBE().highestSignal);

View File

@@ -117,7 +117,7 @@ public class VoltMeterBlockEntity extends SmartBlockEntity implements IHaveGoggl
CURRENT("Current","A",16),
RESISTANCE("Resistance","A",500),
HIGH_RESISTANCE("Resistance (High)","Ω",500),
POWER("Power","A",5000)
POWER("Power","A",5000),
;

View File

@@ -8,6 +8,7 @@ import com.drmangotea.tfmg.content.electricity.base.VoltageAlteringBlockEntity;
import com.drmangotea.tfmg.registry.TFMGPackets;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.DirectionalBlock;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
@@ -19,6 +20,7 @@ public class ElectricDiodeBlockEntity extends VoltageAlteringBlockEntity {
public boolean updateInFront = false;
public ElectricDiodeBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
}
@@ -42,20 +44,36 @@ public class ElectricDiodeBlockEntity extends VoltageAlteringBlockEntity {
}
}
@Override
public void lazyTick() {
super.lazyTick();
}
@Override
public int getPowerUsage() {
getOrCreateElectricNetwork().checkForLoops(getBlockPos());
Direction facing = getDirection();
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be && be.getData().getId() != data.getId()) {
if (be.hasElectricitySlot(facing.getOpposite()))
return Math.max(be.getNetworkPowerUsage(this), 0);
return Math.max(be.getNetworkPowerUsage(this), 0);
}
return 0;
}
@Override
public IElectric getControlledBlock() {
Direction facing = getBlockState().hasProperty(DirectionalBlock.FACING) ? getBlockState().getValue(DirectionalBlock.FACING) : getBlockState().getValue(HorizontalDirectionalBlock.FACING).getCounterClockWise();
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be && be.getData().getId() != data.getId()) {
return be;
}
return null;
}
@Override
public float resistance() {
Direction facing = getDirection();
@@ -124,4 +142,19 @@ public class ElectricDiodeBlockEntity extends VoltageAlteringBlockEntity {
sendStuff();
setChanged();
}
public void updateBehind() {
if(!level.isClientSide)
TFMGPackets.getChannel().send(PacketDistributor.ALL.noArg(), new UpdateInFrontPacket(BlockPos.of(getPos())));
Direction facing = getBlockState().hasProperty(FACING) ? getBlockState().getValue(FACING) : getBlockState().getValue(HorizontalDirectionalBlock.FACING).getCounterClockWise();
facing = facing.getOpposite();
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be && be.getData().getId() != data.getId()) {
if (be.hasElectricitySlot(facing.getOpposite())) {
be.updateNextTick();
}
}
sendStuff();
setChanged();
}
}

View File

@@ -1,5 +1,6 @@
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.KineticElectricBlockEntity;
@@ -14,6 +15,7 @@ import net.createmod.catnip.math.AngleHelper;
import net.createmod.catnip.math.VecHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
@@ -29,11 +31,24 @@ public class ElectricMotorBlockEntity extends KineticElectricBlockEntity {
public static final int MAX_SPEED = 256;
protected ScrollValueBehaviour generatedSpeed;
public boolean delayedUpdate = false;
public float testSpeed = 0;
public ElectricMotorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
}
@Override
public void tick() {
super.tick();
if(delayedUpdate){
updateNextTick();
delayedUpdate = false;
}
}
@Override
public void addBehaviours(List<BlockEntityBehaviour> behaviours) {
super.addBehaviours(behaviours);
@@ -56,6 +71,18 @@ public class ElectricMotorBlockEntity extends KineticElectricBlockEntity {
super.notifyNetworkAboutSpeedChange();
}
@Override
protected void write(CompoundTag compound, boolean clientPacket) {
super.write(compound, clientPacket);
compound.putFloat("MotorSpeed",getSpeed());
}
@Override
protected void read(CompoundTag compound, boolean clientPacket) {
super.read(compound, clientPacket);
testSpeed = compound.getFloat("MotorSpeed");
}
@Override
public void onNetworkChanged(int oldVoltage, int oldPower) {
if (oldPower != getPowerUsage() || oldVoltage != data.voltage) {
@@ -73,8 +100,14 @@ public class ElectricMotorBlockEntity extends KineticElectricBlockEntity {
if (!canWork())
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()));
return 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;
}
TFMG.LOGGER.debug("SPEED: "+speed+" "+generatedSpeed.getValue()+" "+data.getVoltage()/2);
testSpeed = 0;
return speed;
//}
@@ -88,6 +121,8 @@ public class ElectricMotorBlockEntity extends KineticElectricBlockEntity {
return true;
}
@Override
public float resistance() {

View File

@@ -234,10 +234,7 @@ public class ElectricPumpBlockEntity extends PumpBlockEntity implements IElectri
}
@Override
public int getPowerPercentage() {
return powerPercentage;
}
@Override
public float resistance() {
@@ -340,14 +337,7 @@ public class ElectricPumpBlockEntity extends PumpBlockEntity implements IElectri
return data.networkResistance;
}
@Override
public void setWattage(int newWattage) {
}
@Override
public void setPowerPercentage(int percentage) {
powerPercentage = percentage;
}
@Override
public void setNetwork(long network) {

View File

@@ -38,8 +38,9 @@ public class ElectricSwitchBlockEntity extends ElectricDiodeBlockEntity {
protected void analogSignalChanged(int newSignal) {
signal = newSignal;
updateNextTick();
updateInFrontNextTick();
updateNextTick();
}

View File

@@ -1,9 +1,12 @@
package com.drmangotea.tfmg.content.electricity.utilities.transformer;
import com.drmangotea.tfmg.TFMG;
import com.drmangotea.tfmg.base.blocks.TFMGHorizontalDirectionalBlock;
import com.drmangotea.tfmg.content.electricity.base.IElectric;
import com.drmangotea.tfmg.content.electricity.base.UpdateInFrontPacket;
import com.drmangotea.tfmg.content.electricity.base.VoltageAlteringBlockEntity;
import com.drmangotea.tfmg.registry.TFMGPackets;
import com.simibubi.create.foundation.utility.CreateLang;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
@@ -13,8 +16,10 @@ import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.DirectionalBlock;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.network.PacketDistributor;
import java.util.List;
@@ -42,6 +47,15 @@ public class TransformerBlockEntity extends VoltageAlteringBlockEntity {
return coilRatio == 0 ? 0 : getPowerUsage();
}
@Override
public IElectric getControlledBlock() {
Direction facing = getBlockState().hasProperty(DirectionalBlock.FACING) ? getBlockState().getValue(DirectionalBlock.FACING) : getBlockState().getValue(HorizontalDirectionalBlock.FACING).getCounterClockWise();
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be && be.getData().getId() != data.getId()) {
return be;
}
return null;
}
@Override
public void tick() {
super.tick();
@@ -67,12 +81,15 @@ public class TransformerBlockEntity extends VoltageAlteringBlockEntity {
@Override
public int getPowerUsage() {
Direction facing = getDirection();
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be && be.getData().getId() != data.getId()) {
if (be.hasElectricitySlot(facing.getOpposite()))
return Math.max(be.getNetworkPowerUsage(this), 0);
if (be.hasElectricitySlot(facing.getOpposite())) {
return Math.max(be.getNetworkPowerUsage(this), 0);
}
}
return 0;
@@ -140,7 +157,6 @@ public class TransformerBlockEntity extends VoltageAlteringBlockEntity {
@Override
public void onNetworkChanged(int oldVoltage, int oldPower) {
super.onNetworkChanged(oldVoltage, oldPower);
if (oldVoltage != getData().getVoltage() || oldPower != getPowerUsage()) {
updateInFront = true;
}
@@ -148,6 +164,12 @@ public class TransformerBlockEntity extends VoltageAlteringBlockEntity {
setChanged();
}
@Override
public void updateNetwork() {
super.updateNetwork();
updateInFront();
}
@Override
public void remove() {
@@ -162,10 +184,12 @@ public class TransformerBlockEntity extends VoltageAlteringBlockEntity {
updateInFront = true;
}
public void updateInFront(){
public void updateInFront() {
Direction facing = getBlockState().getValue(FACING).getCounterClockWise();
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be) {
if(!level.isClientSide)
TFMGPackets.getChannel().send(PacketDistributor.ALL.noArg(), new UpdateInFrontPacket(BlockPos.of(getPos())));
Direction facing = getBlockState().hasProperty(DirectionalBlock.FACING) ? getBlockState().getValue(DirectionalBlock.FACING) : getBlockState().getValue(HorizontalDirectionalBlock.FACING).getCounterClockWise();
if (level.getBlockEntity(getBlockPos().relative(facing)) instanceof IElectric be && be.getData().getId() != data.getId()) {
if (be.hasElectricitySlot(facing.getOpposite())) {
be.updateNextTick();

View File

@@ -279,7 +279,7 @@ public abstract class AbstractEngineBlockEntity extends KineticElectricBlockEnti
signal = compound.getInt("Signal");
if (hasEngineController())
engineController = BlockPos.of(compound.getLong("EngineController"));
rpm = compound.getFloat("RPM");
fuelInjectionRate = compound.getFloat("RPM");
// if (isController()) {
// if (!BlockPos.of(compound.getLong("ControllerPos")).equals(new BlockPos(0, 0, 0)))
@@ -305,8 +305,8 @@ public abstract class AbstractEngineBlockEntity extends KineticElectricBlockEnti
compound.putBoolean("Reverse", reverse);
compound.putInt("Signal", signal);
if (hasEngineController())
compound.putLong("EngineController", engineController.asLong());
compound.putFloat("RPM", rpm);
compound.putLong("EngineController", engineController.asLong());
compound.putFloat("RPM", fuelInjectionRate);
compound.put("FuelTank", fuelTank.writeToNBT(new CompoundTag()));

View File

@@ -64,6 +64,7 @@ public class EngineBlock extends HorizontalKineticBlock {
engineController.engineStarted = false;
engineController.accelerationRate = 0;
engineController.shift = TransmissionUpgrade.TransmissionState.NEUTRAL;
be.shift = TransmissionUpgrade.TransmissionState.NEUTRAL;
engineController.engine = null;
engineController.enginePos = null;
engineController.disconnectEngine();

View File

@@ -1,14 +1,10 @@
package com.drmangotea.tfmg.content.engines.engine_controller;
import com.drmangotea.tfmg.TFMG;
import com.drmangotea.tfmg.base.TFMGUtils;
import com.drmangotea.tfmg.content.engines.base.AbstractEngineBlockEntity;
import com.drmangotea.tfmg.content.engines.types.AbstractSmallEngineBlockEntity;
import com.drmangotea.tfmg.content.engines.upgrades.TransmissionUpgrade;
import com.simibubi.create.AllItems;
import com.simibubi.create.api.equipment.goggles.IHaveGoggleInformation;
import com.simibubi.create.content.redstone.link.RedstoneLinkNetworkHandler;
import com.simibubi.create.content.redstone.link.controller.LinkedControllerClientHandler;
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
import com.simibubi.create.foundation.utility.CreateLang;
@@ -28,7 +24,6 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
@@ -95,7 +90,7 @@ public class EngineControllerBlockEntity extends SmartBlockEntity implements IHa
compound.putLong("EnginePos", enginePos.asLong());
compound.putString("Shift", shift.name());
compound.putBoolean("EngineStarted",engineStarted);
compound.putBoolean("EngineStarted", engineStarted);
compound.put("FrequencyItems", frequencyItems.serializeNBT());
@@ -109,8 +104,8 @@ public class EngineControllerBlockEntity extends SmartBlockEntity implements IHa
enginePos = BlockPos.of(compound.getLong("EnginePos"));
engineStarted = compound.getBoolean("EngineStarted");
if(engineStarted&&accelerationRate==0)
accelerationRate =4;
if (engineStarted && accelerationRate == 0)
accelerationRate = 4;
frequencyItems.deserializeNBT(compound.getCompound("FrequencyItems"));
shift = TransmissionUpgrade.TransmissionState.valueOf(compound.getString("Shift"));
user = compound.hasUUID("User") ? compound.getUUID("User") : null;
@@ -123,6 +118,7 @@ public class EngineControllerBlockEntity extends SmartBlockEntity implements IHa
TransmissionUpgrade.TransmissionState state = TransmissionUpgrade.TransmissionState.values()[i];
if (state == shift && i + 1 <= max) {
shift = TransmissionUpgrade.TransmissionState.values()[i + 1];
updateShift();
break;
}
@@ -131,6 +127,19 @@ public class EngineControllerBlockEntity extends SmartBlockEntity implements IHa
setChanged();
}
public void updateShift() {
if (enginePos != null)
if (level.getBlockEntity(enginePos) instanceof AbstractSmallEngineBlockEntity be) {
be.getControllerBE().shift = shift;
be.getControllerBE().updateGeneratedRotation();
if(be.getControllerBE().engineLength()>1){
if(level.getBlockEntity(BlockPos.of(be.getControllerBE().engines.get(be.getControllerBE().engineLength()-1)))instanceof AbstractSmallEngineBlockEntity be2){
be2.updateGeneratedRotation();
}
}
}
}
@Override
public void destroy() {
super.destroy();
@@ -145,6 +154,7 @@ public class EngineControllerBlockEntity extends SmartBlockEntity implements IHa
TransmissionUpgrade.TransmissionState state = TransmissionUpgrade.TransmissionState.values()[i];
if (state == shift && i - 1 >= 0) {
shift = TransmissionUpgrade.TransmissionState.values()[i - 1];
updateShift();
break;
}
}
@@ -257,7 +267,7 @@ public class EngineControllerBlockEntity extends SmartBlockEntity implements IHa
if (enginePos != null && (engine == null)) {
if (level.getBlockEntity(enginePos) instanceof AbstractSmallEngineBlockEntity be) {
engine = be;
engine.getControllerBE().highestSignal=4;
engine.getControllerBE().highestSignal = 4;
}
}

View File

@@ -48,6 +48,9 @@ import static com.simibubi.create.content.kinetics.base.HorizontalKineticBlock.H
public abstract class AbstractSmallEngineBlockEntity extends AbstractEngineBlockEntity {
public Optional<? extends EngineUpgrade> upgrade = Optional.empty();
public TransmissionUpgrade.TransmissionState shift = TransmissionUpgrade.TransmissionState.NEUTRAL;
int oil = 0;
int coolingFluid = 0;
@@ -66,7 +69,7 @@ public abstract class AbstractSmallEngineBlockEntity extends AbstractEngineBlock
public int getFuelConsumption() {
if (getGeneratedSpeed() == 0)
if (rpm == 0)
return 0;
@@ -153,7 +156,7 @@ public abstract class AbstractSmallEngineBlockEntity extends AbstractEngineBlock
protected void read(CompoundTag compound, boolean clientPacket) {
if (EngineUpgrade.getUpgrades().get(ItemStack.of(compound.getCompound("UpgradeItem")).getItem()) != null)
upgrade = Optional.of(EngineUpgrade.getUpgrades().get(ItemStack.of(compound.getCompound("UpgradeItem")).getItem()));
shift = TransmissionUpgrade.TransmissionState.valueOf(compound.getString("Shift"));
oil = compound.getInt("Oil");
coolingFluid = compound.getInt("CoolingFluid");
componentsInventory.deserializeNBT(compound.getCompound("Components"));
@@ -232,7 +235,7 @@ public abstract class AbstractSmallEngineBlockEntity extends AbstractEngineBlock
@Override
protected void write(CompoundTag compound, boolean clientPacket) {
compound.putLong("Controller", controller.asLong());
compound.putString("Shift", shift.name());
if (controller != null) {
compound.putLong("ControllerPos", controller.asLong());
} else compound.remove("ControllerPos");
@@ -300,7 +303,7 @@ public abstract class AbstractSmallEngineBlockEntity extends AbstractEngineBlock
if (hasLevel())
if (level.getBlockEntity(controller) instanceof AbstractEngineBlockEntity controller) {
if (level.getBlockEntity(controller) instanceof AbstractSmallEngineBlockEntity controller) {
if (controller.fuelTank.isEmpty())
return 0;
if (!controller.canWork())
@@ -309,6 +312,22 @@ public abstract class AbstractSmallEngineBlockEntity extends AbstractEngineBlock
if (reverse)
speed = speed * -1;
if (controller.hasEngineController()) {
speed = switch (controller.shift) {
case REVERSE -> speed * -0.3f;
case NEUTRAL -> 0;
case SHIFT_1 -> speed * 0.2f;
case SHIFT_2 -> speed * 0.4f;
case SHIFT_3 -> speed * 0.6f;
case SHIFT_4 -> speed * 0.8f;
case SHIFT_5 -> speed;
case SHIFT_6 -> speed * 1.2f;
};
}
return convertToDirection(Math.min((int) speed, 256), getBlockState().getValue(HORIZONTAL_FACING));
}
@@ -456,13 +475,14 @@ public abstract class AbstractSmallEngineBlockEntity extends AbstractEngineBlock
return controller.equals(getBlockPos());
}
@Override
public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
if (controller.asLong() == getBlockPos().asLong())
CreateLang.text("CONTROLLER").forGoggles(tooltip);
CreateLang.text("Shift " + shift.toString()).forGoggles(tooltip);
CreateLang.text("Speed Efficiency " + getSpeedEfficiency()).forGoggles(tooltip);
CreateLang.text("Efficiency " + efficiencyModifier()).forGoggles(tooltip);
CreateLang.text("Fuel Consumption " + getFuelConsumption()).forGoggles(tooltip);

View File

@@ -19,7 +19,7 @@ import static net.minecraft.world.level.block.HorizontalDirectionalBlock.FACING;
public class TransmissionUpgrade extends EngineUpgrade{
TransmissionState shift = TransmissionState.NEUTRAL;

View File

@@ -120,6 +120,12 @@ public class SpoolItem extends Item {
//
CableConnection connection1 = new CableConnection(be.getCablePosition(), otherBE.getCablePosition(), otherBE.getBlockPos(),type,true);
CableConnection connection2 = new CableConnection(otherBE.getCablePosition(), be.getCablePosition(), be.getBlockPos(),type,false);
float wireCost = (connection1.getLength()/8);
if(stack.getOrCreateTag().getInt("Amount")<wireCost)
return InteractionResult.PASS;
if(be.connections.contains(connection1)||otherBE.connections.contains(connection1)){
if (level.isClientSide)
player.displayClientMessage(CreateLang.translateDirect("wires.connection_already_created")
@@ -136,7 +142,7 @@ public class SpoolItem extends Item {
}
// connectedBe1.wiresUpdated();
stack.getOrCreateTag().putInt("Amount", (int) (stack.getOrCreateTag().getInt("Amount")-(wireCost*125)));
be.player = null;
otherBE.player = null;
be.setChanged();

View File

@@ -53,7 +53,9 @@ public class ElectrodeHolderBlockEntity extends ElectricBlockEntity implements I
public float resistance() {
if (electrodeType != ElectrodeType.NONE) {
return 20;
if(electrodeType == ElectrodeType.GRAPHITE) {
return 200;
}else return 100;
}
return 0;

View File

@@ -94,6 +94,7 @@
"create.recipe.casting": "Casting",
"create.recipe.coking": "Coking",
"create.recipe.polarizing": "Polarizing",
"create.recipe.chemical_vat": "Chemical Vat",
"tfmg.keyinfo.custom_button": "Engine Controller Custom Button",
"tfmg.keyinfo.engine_start": "Start Engine",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 467 B

After

Width:  |  Height:  |  Size: 530 B