diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index 178a010d5..86f16c969 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -4,6 +4,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import com.simibubi.create.modules.ModuleLoadedCondition; +import com.simibubi.create.modules.contraptions.TorquePropagator; import com.simibubi.create.modules.contraptions.receivers.constructs.MovingConstructHandler; import com.simibubi.create.modules.logistics.FrequencyHandler; import com.simibubi.create.modules.logistics.management.LogisticalNetworkHandler; @@ -42,6 +43,7 @@ public class Create { public static FrequencyHandler frequencyHandler; public static MovingConstructHandler constructHandler; public static LogisticalNetworkHandler logisticalNetworkHandler; + public static TorquePropagator torquePropagator; public static LogisticianHandler logisticianHandler; public static ModConfig config; @@ -66,6 +68,7 @@ public class Create { frequencyHandler = new FrequencyHandler(); constructHandler = new MovingConstructHandler(); logisticalNetworkHandler = new LogisticalNetworkHandler(); + torquePropagator = new TorquePropagator(); CraftingHelper.register(new ModuleLoadedCondition.Serializer()); AllPackets.registerPackets(); diff --git a/src/main/java/com/simibubi/create/Events.java b/src/main/java/com/simibubi/create/Events.java index 145592020..e18411124 100644 --- a/src/main/java/com/simibubi/create/Events.java +++ b/src/main/java/com/simibubi/create/Events.java @@ -46,6 +46,7 @@ public class Events { Create.frequencyHandler.onLoadWorld(world); Create.constructHandler.onLoadWorld(world); Create.logisticalNetworkHandler.onLoadWorld(world); + Create.torquePropagator.onLoadWorld(world); } @SubscribeEvent @@ -54,6 +55,7 @@ public class Events { Create.frequencyHandler.onUnloadWorld(world); Create.constructHandler.onUnloadWorld(world); Create.logisticalNetworkHandler.onUnloadWorld(world); + Create.torquePropagator.onUnloadWorld(world); } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/foundation/utility/Lang.java b/src/main/java/com/simibubi/create/foundation/utility/Lang.java index a763c5ced..81196ba1a 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/Lang.java +++ b/src/main/java/com/simibubi/create/foundation/utility/Lang.java @@ -6,8 +6,12 @@ import java.util.Locale; import com.simibubi.create.Create; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TranslationTextComponent; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; public class Lang { @@ -18,11 +22,26 @@ public class Lang { private static TranslationTextComponent getTranslationComponent(String key, Object... args) { return new TranslationTextComponent(Create.ID + "." + key, args); } - + public static void sendStatus(PlayerEntity player, String key, Object... args) { player.sendStatusMessage(getTranslationComponent(key, args), true); } - + + // Deprecated so simi doensn't forget to remove debug calls + @OnlyIn(value = Dist.CLIENT) + @Deprecated + public static void debugChat(String message) { + if (Minecraft.getInstance().player != null) + Minecraft.getInstance().player.sendStatusMessage(new StringTextComponent(message), false); + } + + @OnlyIn(value = Dist.CLIENT) + @Deprecated + public static void debugMessage(String message) { + if (Minecraft.getInstance().player != null) + Minecraft.getInstance().player.sendStatusMessage(new StringTextComponent(message), true); + } + public static List translatedOptions(String prefix, String... keys) { List result = new ArrayList<>(keys.length); for (String key : keys) { @@ -30,9 +49,9 @@ public class Lang { } return result; } - + public static String asId(String name) { return name.toLowerCase(Locale.ENGLISH); } - + } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/KineticNetwork.java b/src/main/java/com/simibubi/create/modules/contraptions/KineticNetwork.java new file mode 100644 index 000000000..583da6d5e --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/contraptions/KineticNetwork.java @@ -0,0 +1,118 @@ +package com.simibubi.create.modules.contraptions; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.modules.contraptions.base.KineticTileEntity; + +public class KineticNetwork { + + public UUID id; + private float stressCapacityPool; + private float maxStress; + private float currentStress; + public boolean initialized; + + public Map sources; + public Set members; + + public KineticNetwork() { + id = UUID.randomUUID(); + maxStress = stressCapacityPool = 0; + setCurrentStress(0); + sources = new HashMap<>(); + members = new HashSet<>(); + } + + public void initFromTE(KineticTileEntity te) { + maxStress = stressCapacityPool = te.maxStress; + currentStress = te.currentStress; + initialized = true; + addSilently(te); + } + + public void addSilently(KineticTileEntity te) { + if (members.contains(te)) + return; + if (te.isSource()) { + float capacity = te.getAddedStressCapacity(); + stressCapacityPool -= capacity; + sources.put(te, capacity); + } + members.add(te); + } + + public void add(KineticTileEntity te) { + if (members.contains(te)) + return; + + Lang.debugChat(te.getType().getRegistryName().getPath() + " added to Network"); + + te.setNetworkID(this.id); + + if (te.isSource()) { + float capacity = te.getAddedStressCapacity(); + sources.put(te, capacity); + updateMaxStress(); + } + members.add(te); + setCurrentStress(getCurrentStress() + te.getStressApplied()); + sync(); + } + + public void updateCapacityFor(KineticTileEntity te, float capacity) { + sources.put(te, capacity); + updateMaxStress(); + } + + public void remove(KineticTileEntity te) { + if (!members.contains(te)) + return; + + Lang.debugChat(te.getType().getRegistryName().getPath() + " removed from Network"); + + if (te.isSource()) { + sources.remove(te); + updateMaxStress(); + } + members.remove(te); + setCurrentStress(getCurrentStress() - te.getStressApplied()); + sync(); + } + + public void sync() { + for (KineticTileEntity te : members) { + te.sync(id, getMaxStress(), getCurrentStress()); + } + } + + public float getMaxStress() { + return maxStress; + } + + private void updateMaxStress() { + float presentCapacity = 0; + for (Float cap : sources.values()) + presentCapacity += cap; + float newMaxStress = presentCapacity + stressCapacityPool; + if (maxStress != newMaxStress) { + maxStress = newMaxStress; + sync(); + } + Lang.debugChat("Current Stress level: " + currentStress + "/" + maxStress); + } + + public float getCurrentStress() { + return currentStress; + } + + public void setCurrentStress(float currentStress) { + this.currentStress = currentStress; + Lang.debugChat("Current Stress level: " + currentStress + "/" + maxStress); + } + +} diff --git a/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java b/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java index 39b037ba9..7781a6fc0 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java @@ -173,8 +173,7 @@ public class RotationPropagator { return; if (!worldIn.isBlockPresent(pos)) return; - - if (addedTE.getSpeed() != 0) { + if (addedTE.speed != 0) { propagateNewSource(addedTE); return; } @@ -182,16 +181,16 @@ public class RotationPropagator { for (KineticTileEntity neighbourTE : getConnectedNeighbours(addedTE)) { final float speedModifier = getRotationSpeedModifier(neighbourTE, addedTE); - if (neighbourTE.getSpeed() == 0) + if (neighbourTE.speed == 0) continue; if (neighbourTE.hasSource() && neighbourTE.getSource().equals(addedTE.getPos())) { - addedTE.setSpeed(neighbourTE.getSpeed() * speedModifier); + addedTE.setSpeed(neighbourTE.speed * speedModifier); addedTE.onSpeedChanged(); addedTE.sendData(); continue; } - addedTE.setSpeed(neighbourTE.getSpeed() * speedModifier); + addedTE.setSpeed(neighbourTE.speed * speedModifier); addedTE.setSource(neighbourTE.getPos()); addedTE.onSpeedChanged(); addedTE.sendData(); @@ -210,18 +209,63 @@ public class RotationPropagator { World world = updateTE.getWorld(); for (KineticTileEntity neighbourTE : getConnectedNeighbours(updateTE)) { - final float newSpeed = updateTE.getSpeed() * getRotationSpeedModifier(updateTE, neighbourTE); + float modFromTo = getRotationSpeedModifier(updateTE, neighbourTE); + float modToFrom = getRotationSpeedModifier(neighbourTE, updateTE); + final float newSpeed = updateTE.speed * modFromTo; + float oppositeSpeed = neighbourTE.speed * modToFrom; - if ((neighbourTE.isSource()) - || neighbourTE.hasSource() && !neighbourTE.getSource().equals(updateTE.getPos())) { - if (neighbourTE.getSpeed() != newSpeed || Math.abs(newSpeed) > parameters.maxRotationSpeed.get()) { - world.destroyBlock(pos, true); - return; + boolean incompatible = Math.signum(newSpeed) != Math.signum(neighbourTE.speed) + && (newSpeed != 0 && neighbourTE.speed != 0); + + boolean tooFast = Math.abs(newSpeed) > parameters.maxRotationSpeed.get(); + if (tooFast) { + world.destroyBlock(pos, true); + return; + } + + boolean isSource = neighbourTE.isSource(); + boolean hasSource = neighbourTE.hasSource(); + boolean poweredBySomethingElse = isSource + || hasSource && !neighbourTE.getSource().equals(updateTE.getPos()); + + if (poweredBySomethingElse) { + if (neighbourTE.speed != newSpeed) { + if (incompatible) { + // Opposite directions + world.destroyBlock(pos, true); + return; + + } else { + // Same direction: overpower the slower speed + if (Math.abs(oppositeSpeed) > Math.abs(updateTE.speed)) { + // Neighbour faster, overpower the incoming tree + updateTE.setSource(neighbourTE.getPos()); + updateTE.setSpeed(neighbourTE.speed * getRotationSpeedModifier(neighbourTE, updateTE)); + updateTE.onSpeedChanged(); + updateTE.sendData(); + propagateNewSource(updateTE); + return; + } + if (Math.abs(newSpeed) > Math.abs(neighbourTE.speed)) { + // Current faster, overpower the neighbours' tree + + if (updateTE.hasSource() && updateTE.getSource().equals(neighbourTE.getPos())) { + updateTE.removeSource(); + } + + neighbourTE.setSource(updateTE.getPos()); + neighbourTE.setSpeed(updateTE.speed * getRotationSpeedModifier(updateTE, neighbourTE)); + neighbourTE.onSpeedChanged(); + neighbourTE.sendData(); + propagateNewSource(neighbourTE); + continue; + } + } } continue; } - if (neighbourTE.getSpeed() == newSpeed) + if (neighbourTE.speed == newSpeed) continue; neighbourTE.setSpeed(newSpeed); @@ -245,7 +289,7 @@ public class RotationPropagator { return; if (removedTE == null) return; - if (removedTE.getSpeed() == 0) + if (removedTE.speed == 0) return; for (BlockPos neighbourPos : getPotentialNeighbourLocations(removedTE)) { @@ -254,7 +298,7 @@ public class RotationPropagator { continue; final KineticTileEntity neighbourTE = (KineticTileEntity) worldIn.getTileEntity(neighbourPos); - if (!neighbourTE.hasSource() || !neighbourTE.getSource().equals(pos) || neighbourTE.isSource()) + if (!neighbourTE.hasSource() || !neighbourTE.getSource().equals(pos)) continue; propagateMissingSource(neighbourTE); @@ -283,11 +327,6 @@ public class RotationPropagator { currentTE.sendData(); for (KineticTileEntity neighbourTE : getConnectedNeighbours(currentTE)) { - if (neighbourTE.isSource()) { - potentialNewSources.add(neighbourTE); - continue; - } - if (!neighbourTE.hasSource()) continue; @@ -296,6 +335,10 @@ public class RotationPropagator { continue; } + if (neighbourTE.isSource()) { + potentialNewSources.add(neighbourTE); + } + frontier.add(neighbourTE.getPos()); } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/TorquePropagator.java b/src/main/java/com/simibubi/create/modules/contraptions/TorquePropagator.java new file mode 100644 index 000000000..83a715886 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/contraptions/TorquePropagator.java @@ -0,0 +1,50 @@ +package com.simibubi.create.modules.contraptions; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import com.simibubi.create.Create; +import com.simibubi.create.modules.contraptions.base.KineticTileEntity; + +import net.minecraft.client.Minecraft; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.world.IWorld; + +public class TorquePropagator { + + static Map> networks = new HashMap<>(); + + public void onLoadWorld(IWorld world) { + networks.put(world, new HashMap<>()); + Create.logger.debug("Prepared Kinetic Network Space for " + world.getDimension().getType().getRegistryName()); + } + + public void onUnloadWorld(IWorld world) { + networks.remove(world); + Create.logger.debug("Removed Kinetic Network Space for " + world.getDimension().getType().getRegistryName()); + } + + public KineticNetwork getNetworkFor(KineticTileEntity te) { + UUID id = te.getNetworkID(); + KineticNetwork network; + Map map = networks.get(te.getWorld()); + if (id == null) { + network = new KineticNetwork(); + + //TODO + Minecraft.getInstance().player.sendStatusMessage(new StringTextComponent(te.getType().getRegistryName().getPath() + " created new Network"), false); + + map.put(id, network); + } else { + if (!map.containsKey(id)) { + network = new KineticNetwork(); + network.id = te.getNetworkID(); + map.put(id, network); + } + network = map.get(id); + } + return network; + } + +} diff --git a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntity.java index 961436eb3..7d2561a34 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntity.java @@ -2,70 +2,129 @@ package com.simibubi.create.modules.contraptions.base; import java.util.Optional; import java.util.Random; +import java.util.UUID; +import com.simibubi.create.Create; import com.simibubi.create.foundation.block.SyncedTileEntity; +import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.modules.contraptions.KineticNetwork; import com.simibubi.create.modules.contraptions.RotationPropagator; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.NBTUtil; import net.minecraft.particles.RedstoneParticleData; +import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; -public abstract class KineticTileEntity extends SyncedTileEntity { +public abstract class KineticTileEntity extends SyncedTileEntity implements ITickableTileEntity { - protected float speed; - protected float force; + public float speed; protected Optional source; + public boolean reActivateSource; + + public float maxStress; + public float currentStress; + public UUID networkID; + protected boolean overStressed; + protected boolean initNetwork; public KineticTileEntity(TileEntityType typeIn) { super(typeIn); speed = 0; - force = 0; source = Optional.empty(); } - + + public void sync(UUID networkID, float maxStress, float currentStress) { + this.setNetworkID(networkID); + this.maxStress = maxStress; + this.currentStress = currentStress; + boolean overStressed = maxStress < currentStress; + if (overStressed != this.overStressed) { + + Lang.debugChat(getType().getRegistryName().getPath() + " jammed (" + currentStress + "/" + maxStress + ")"); + + this.overStressed = overStressed; + sendData(); + } + } + + public float getAddedStressCapacity() { + return 0; + } + + public float getStressApplied() { + return isSource() ? 0 : 1; + } + + protected void notifyStressChange(float diff) { + KineticNetwork network = getNetwork(); + network.setCurrentStress(network.getCurrentStress() + diff); + network.sync(); + } + + protected void notifyStressCapacityChange(float capacity) { + getNetwork().updateCapacityFor(this, capacity); + } + @Override public boolean hasFastRenderer() { return true; } - + public void onSpeedChanged() { +// if (isSource() && !world.isRemote) { +// if (networkID == null) +// getNetwork().add(this); +// } } - + @Override public void remove() { if (world.isRemote) { super.remove(); return; } + if (hasNetwork()) { + getNetwork().remove(this); + } RotationPropagator.handleRemoved(getWorld(), getPos(), this); super.remove(); } @Override public CompoundNBT write(CompoundNBT compound) { - compound.putFloat("Speed", getSpeed()); - compound.putFloat("Force", getForce()); - + compound.putFloat("Speed", speed); if (hasSource()) compound.put("Source", NBTUtil.writeBlockPos(getSource())); + if (hasNetwork()) { + compound.putFloat("MaxStress", maxStress); + compound.putFloat("Stress", currentStress); + compound.put("Id", NBTUtil.writeUniqueId(getNetworkID())); + } + return super.write(compound); } @Override public void read(CompoundNBT compound) { setSpeed(compound.getFloat("Speed")); - setForce(compound.getFloat("Force")); - setSource(null); if (compound.contains("Source")) { CompoundNBT tagSource = compound.getCompound("Source"); setSource(NBTUtil.readBlockPos(tagSource)); } + if (compound.contains("Id")) { + maxStress = compound.getFloat("MaxStress"); + currentStress = compound.getFloat("Stress"); + overStressed = maxStress < currentStress; + setNetworkID(NBTUtil.readUniqueId(compound.getCompound("Id"))); + initNetwork = true; + } + super.read(compound); } @@ -74,6 +133,8 @@ public abstract class KineticTileEntity extends SyncedTileEntity { } public float getSpeed() { + if (overStressed) + return 0; return speed; } @@ -90,14 +151,6 @@ public abstract class KineticTileEntity extends SyncedTileEntity { } } - public float getForce() { - return force; - } - - public void setForce(float force) { - this.force = force; - } - public boolean hasSource() { return source.isPresent(); } @@ -113,26 +166,95 @@ public abstract class KineticTileEntity extends SyncedTileEntity { public void setSource(BlockPos source) { this.source = Optional.ofNullable(source); + + if (world == null || world.isRemote) + return; + if (hasNetwork()) { + getNetwork().remove(this); + networkID = null; + } + if (source == null) + return; + KineticTileEntity sourceTe = (KineticTileEntity) world.getTileEntity(source); + if (sourceTe == null) + return; + Create.torquePropagator.getNetworkFor(sourceTe).add(this); } public void removeSource() { + if (hasSource() && isSource()) + reActivateSource = true; + this.source = Optional.empty(); + + if (hasNetwork() && !isSource()) { + getNetwork().remove(this); + networkID = null; + } + setSpeed(0); onSpeedChanged(); } - + + public KineticNetwork getNetwork() { + KineticNetwork networkFor = Create.torquePropagator.getNetworkFor(this); + if (!networkFor.initialized) { + networkFor.add(this); + networkFor.initialized = true; + } + return networkFor; + } + + public boolean hasNetwork() { + return networkID != null; + } + public void applyNewSpeed(float speed) { detachKinetics(); this.speed = speed; attachKinetics(); } - + public void attachKinetics() { RotationPropagator.handleAdded(world, pos, this); } - + public void detachKinetics() { RotationPropagator.handleRemoved(world, pos, this); } + public UUID getNetworkID() { + return networkID; + } + + public void setNetworkID(UUID networkID) { + this.networkID = networkID; + } + + /** + * Callback for source blocks to re-apply their speed when an overpowering + * source is removed + */ + public void reActivateSource() { + + } + + @Override + public void tick() { + if (reActivateSource) { + reActivateSource(); + reActivateSource = false; + } + + if (initNetwork) { + initNetwork = false; + KineticNetwork network = getNetwork(); + if (network.initialized) { + network.addSilently(this); + } else { + network.initFromTE(this); + } + } + } + } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorTileEntity.java index d1519b2cb..f859e518f 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorTileEntity.java @@ -5,10 +5,9 @@ import com.simibubi.create.AllTileEntities; import com.simibubi.create.CreateConfig; import com.simibubi.create.modules.contraptions.base.KineticTileEntity; -import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.util.math.MathHelper; -public class MotorTileEntity extends KineticTileEntity implements ITickableTileEntity { +public class MotorTileEntity extends KineticTileEntity { public static final int DEFAULT_SPEED = 64; public int newSpeed; @@ -17,8 +16,14 @@ public class MotorTileEntity extends KineticTileEntity implements ITickableTileE public MotorTileEntity() { super(AllTileEntities.MOTOR.type); setSpeed(DEFAULT_SPEED); + lastModified = -1; } + @Override + public float getAddedStressCapacity() { + return 500; + } + @Override public boolean hasFastRenderer() { return true; @@ -34,6 +39,13 @@ public class MotorTileEntity extends KineticTileEntity implements ITickableTileE super.setSpeed(speed); newSpeed = (int) speed; } + + @Override + public void removeSource() { + float speed = this.speed; + super.removeSource(); + setSpeed(speed); + } public int getSpeedValue() { if (world.isRemote) @@ -56,6 +68,8 @@ public class MotorTileEntity extends KineticTileEntity implements ITickableTileE @Override public void tick() { + super.tick(); + if (!world.isRemote) return; if (lastModified == -1) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/generators/WaterWheelBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/generators/WaterWheelBlock.java index 25dfc1928..36bbac595 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/generators/WaterWheelBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/generators/WaterWheelBlock.java @@ -83,7 +83,7 @@ public class WaterWheelBlock extends HorizontalKineticBlock { flowVec = flowVec.scale(f.getAxisDirection().getOffset()); boolean clockwise = wf.getAxisDirection() == AxisDirection.POSITIVE; - int clockwiseMultiplier = 1; // No difference. Causes confusion + int clockwiseMultiplier = 2; if (wf.getAxis() == Axis.Z) { if (f.getAxis() == Axis.Y) @@ -103,6 +103,8 @@ public class WaterWheelBlock extends HorizontalKineticBlock { } private void updateWheelSpeed(IWorld world, BlockPos pos) { + if (world.isRemote()) + return; WaterWheelTileEntity te = (WaterWheelTileEntity) world.getTileEntity(pos); if (te == null) return; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/generators/WaterWheelTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/generators/WaterWheelTileEntity.java index f6c2e152b..57bfc0d60 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/generators/WaterWheelTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/generators/WaterWheelTileEntity.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.contraptions.generators; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import com.simibubi.create.AllTileEntities; import com.simibubi.create.modules.contraptions.RotationPropagator; @@ -32,7 +33,7 @@ public class WaterWheelTileEntity extends KineticTileEntity { setFlow(d, compound.getCompound("Flows").getInt(d.getName())); } } - + @Override public AxisAlignedBB getRenderBoundingBox() { return new AxisAlignedBB(pos).grow(1); @@ -45,7 +46,7 @@ public class WaterWheelTileEntity extends KineticTileEntity { for (Direction d : Direction.values()) flows.putInt(d.getName(), this.flows.get(d)); compound.put("Flows", flows); - + return super.write(compound); } @@ -53,19 +54,27 @@ public class WaterWheelTileEntity extends KineticTileEntity { flows.put(direction, speed); } + @Override + public void reActivateSource() { + updateSpeed(); + } + public void updateSpeed() { float speed = 0; for (Integer i : flows.values()) speed += i; if (this.speed != speed) { + hasFlows = speed != 0; + notifyStressCapacityChange(getAddedStressCapacity()); + source = Optional.empty(); RotationPropagator.handleRemoved(world, pos, this); this.setSpeed(speed); - hasFlows = speed != 0; sendData(); RotationPropagator.handleAdded(world, pos, this); } + onSpeedChanged(); } @Override @@ -73,4 +82,12 @@ public class WaterWheelTileEntity extends KineticTileEntity { return hasFlows; } + @Override + public float getAddedStressCapacity() { + float torque = 0; + for (Integer i : flows.values()) + torque += i; + return Math.abs(torque); + } + } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillTileEntity.java index 597087a7b..8c015ad8b 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillTileEntity.java @@ -15,7 +15,6 @@ import net.minecraft.fluid.IFluidState; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.DamageSource; import net.minecraft.util.math.AxisAlignedBB; @@ -25,7 +24,7 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameRules; import net.minecraft.world.server.ServerWorld; -public class DrillTileEntity extends KineticTileEntity implements ITickableTileEntity { +public class DrillTileEntity extends KineticTileEntity { private static final AtomicInteger NEXT_DRILL_ID = new AtomicInteger(); @@ -73,6 +72,8 @@ public class DrillTileEntity extends KineticTileEntity implements ITickableTileE @Override public void tick() { + super.tick(); + if (world.isRemote) return; if (speed == 0) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/EncasedFanTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/EncasedFanTileEntity.java index 2d1a0c6a8..b62bbda53 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/EncasedFanTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/EncasedFanTileEntity.java @@ -6,6 +6,7 @@ import static net.minecraft.util.Direction.AxisDirection.NEGATIVE; import static net.minecraft.util.Direction.AxisDirection.POSITIVE; import java.util.List; +import java.util.Optional; import com.simibubi.create.AllBlockTags; import com.simibubi.create.AllBlocks; @@ -24,7 +25,6 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.item.ItemEntity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.particles.ParticleTypes; -import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.util.DamageSource; import net.minecraft.util.Direction; import net.minecraft.util.SoundCategory; @@ -35,7 +35,7 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; -public class EncasedFanTileEntity extends KineticTileEntity implements ITickableTileEntity { +public class EncasedFanTileEntity extends KineticTileEntity { private static DamageSource damageSourceFire = new DamageSource("create.fan_fire").setDifficultyScaled() .setFireDamage(); @@ -91,14 +91,23 @@ public class EncasedFanTileEntity extends KineticTileEntity implements ITickable return isGenerator; } + @Override + public float getAddedStressCapacity() { + return 50; + } + public void updateGenerator() { boolean shouldGenerate = world.isBlockPowered(pos) && world.isBlockPresent(pos.down()) && blockBelowIsHot(); if (shouldGenerate == isGenerator) return; isGenerator = shouldGenerate; - if (isGenerator) + if (isGenerator) { + notifyStressCapacityChange(getAddedStressCapacity()); removeSource(); + } else { + notifyStressCapacityChange(0); + } applyNewSpeed(isGenerator ? CreateConfig.parameters.generatingFanSpeed.get() : 0); sendData(); } @@ -182,8 +191,16 @@ public class EncasedFanTileEntity extends KineticTileEntity implements ITickable updateFrontBlock(); } + @Override + public void reActivateSource() { + source = Optional.empty(); + applyNewSpeed(isGenerator ? CreateConfig.parameters.generatingFanSpeed.get() : 0); + } + @Override public void tick() { + super.tick(); + if (speed == 0 || isGenerator) return; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalMixerTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalMixerTileEntity.java index fc12ff9c3..2695d66e9 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalMixerTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalMixerTileEntity.java @@ -22,7 +22,6 @@ import net.minecraft.item.crafting.ShapelessRecipe; import net.minecraft.nbt.CompoundNBT; import net.minecraft.particles.ItemParticleData; import net.minecraft.particles.ParticleTypes; -import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction.Axis; import net.minecraft.util.NonNullList; @@ -35,7 +34,7 @@ import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemHandlerHelper; -public class MechanicalMixerTileEntity extends KineticTileEntity implements ITickableTileEntity { +public class MechanicalMixerTileEntity extends KineticTileEntity { public int runningTicks; public int processingTicks; @@ -132,6 +131,7 @@ public class MechanicalMixerTileEntity extends KineticTileEntity implements ITic @Override public void tick() { + super.tick(); if (world.isRemote && lastModified != -1) { if (lastModified++ > 10) { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressTileEntity.java index c4f5d0918..876247563 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressTileEntity.java @@ -13,7 +13,6 @@ import net.minecraft.entity.item.ItemEntity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.particles.ItemParticleData; import net.minecraft.particles.ParticleTypes; -import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvents; import net.minecraft.util.math.AxisAlignedBB; @@ -22,7 +21,7 @@ import net.minecraft.util.math.Vec3d; import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.wrapper.RecipeWrapper; -public class MechanicalPressTileEntity extends KineticTileEntity implements ITickableTileEntity { +public class MechanicalPressTileEntity extends KineticTileEntity { public static class PressingInv extends RecipeWrapper { public PressingInv() { @@ -85,6 +84,8 @@ public class MechanicalPressTileEntity extends KineticTileEntity implements ITic @Override public void tick() { + super.tick(); + if (!running) return; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalBearingTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalBearingTileEntity.java index 05819b281..00f35b07c 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalBearingTileEntity.java @@ -1,5 +1,7 @@ package com.simibubi.create.modules.contraptions.receivers.constructs; +import java.util.Optional; + import com.simibubi.create.AllTileEntities; import com.simibubi.create.modules.contraptions.RotationPropagator; import com.simibubi.create.modules.contraptions.base.KineticTileEntity; @@ -8,7 +10,6 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.nbt.CompoundNBT; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; @@ -18,7 +19,7 @@ import net.minecraft.world.gen.feature.template.Template.BlockInfo; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -public class MechanicalBearingTileEntity extends KineticTileEntity implements ITickableTileEntity { +public class MechanicalBearingTileEntity extends KineticTileEntity { protected RotationConstruct movingConstruct; protected float angle; @@ -41,6 +42,11 @@ public class MechanicalBearingTileEntity extends KineticTileEntity implements IT public double getMaxRenderDistanceSquared() { return super.getMaxRenderDistanceSquared() * 16; } + + @Override + public float getAddedStressCapacity() { + return getWindmillSpeed() * 50; + } @Override public boolean isSource() { @@ -144,10 +150,16 @@ public class MechanicalBearingTileEntity extends KineticTileEntity implements IT getWorld().setBlockState(info.pos.add(pos), Blocks.AIR.getDefaultState(), 67); } + applyWindmillSpeed(); + } + + public void applyWindmillSpeed() { if (isWindmill) { RotationPropagator.handleRemoved(world, pos, this); + source = Optional.empty(); speed = getWindmillSpeed(); RotationPropagator.handleAdded(world, pos, this); + sendData(); } } @@ -176,9 +188,16 @@ public class MechanicalBearingTileEntity extends KineticTileEntity implements IT angle = 0; sendData(); } + + @Override + public void reActivateSource() { + applyWindmillSpeed(); + } @Override public void tick() { + super.tick(); + if (running && RotationConstruct.isFrozen()) disassembleConstruct(); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonTileEntity.java index 19968f290..c9527b66a 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonTileEntity.java @@ -19,7 +19,6 @@ import com.simibubi.create.modules.contraptions.receivers.constructs.MechanicalP import net.minecraft.block.Blocks; import net.minecraft.nbt.CompoundNBT; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.AxisAlignedBB; @@ -30,7 +29,7 @@ import net.minecraft.world.gen.feature.template.Template.BlockInfo; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -public class MechanicalPistonTileEntity extends KineticTileEntity implements ITickableTileEntity { +public class MechanicalPistonTileEntity extends KineticTileEntity { protected PistonContraption movedContraption; protected float offset; @@ -189,6 +188,8 @@ public class MechanicalPistonTileEntity extends KineticTileEntity implements ITi @Override public void tick() { + super.tick(); + if (!world.isRemote && assembleNextTick) { assembleNextTick = false; if (running) { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/GearboxTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/GearboxTileEntityRenderer.java index 586eac9a1..da4088589 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/GearboxTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/GearboxTileEntityRenderer.java @@ -33,7 +33,7 @@ public class GearboxTileEntityRenderer extends KineticTileEntityRenderer { float offset = getRotationOffsetForPosition(te, pos, axis); float angle = (time * te.getSpeed()) % 360; - if (te.getSpeed() != 0) { + if (te.getSpeed() != 0 && te.hasSource()) { BlockPos source = te.getSource().subtract(te.getPos()); Direction sourceFacing = Direction.getFacingFromVector(source.getX(), source.getY(), source.getZ()); if (sourceFacing.getAxis() == direction.getAxis()) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItem.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItem.java index f44a34f02..a6a2c730d 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItem.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItem.java @@ -183,7 +183,7 @@ public class BeltItem extends Item { float speed1 = ((KineticTileEntity) world.getTileEntity(first)).getSpeed(); float speed2 = ((KineticTileEntity) world.getTileEntity(second)).getSpeed(); - if (speed1 != speed2 && speed1 != 0 && speed2 != 0) + if (Math.signum(speed1) != Math.signum(speed2) && speed1 != 0 && speed2 != 0) return false; BlockPos step = new BlockPos(Math.signum(diff.getX()), Math.signum(diff.getY()), Math.signum(diff.getZ())); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntity.java index 93bf50e8e..baa90e188 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntity.java @@ -26,7 +26,6 @@ import net.minecraft.nbt.NBTUtil; import net.minecraft.potion.EffectInstance; import net.minecraft.potion.Effects; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; @@ -36,7 +35,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; -public class BeltTileEntity extends KineticTileEntity implements ITickableTileEntity { +public class BeltTileEntity extends KineticTileEntity { protected BlockPos controller; public Map passengers; @@ -140,6 +139,8 @@ public class BeltTileEntity extends KineticTileEntity implements ITickableTileEn @Override public void tick() { + super.tick(); + if (world != null && trackerUpdateTag != null) { attachmentTracker.readAndSearch(trackerUpdateTag, this); trackerUpdateTag = null; diff --git a/src/main/java/com/simibubi/create/modules/logistics/FrequencyHandler.java b/src/main/java/com/simibubi/create/modules/logistics/FrequencyHandler.java index 97db6644a..12a36701c 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/FrequencyHandler.java +++ b/src/main/java/com/simibubi/create/modules/logistics/FrequencyHandler.java @@ -50,12 +50,12 @@ public class FrequencyHandler { public void onLoadWorld(IWorld world) { connections.put(world, new HashMap<>()); - Create.logger.debug("Prepared Network Space for " + world.getDimension().getType().getRegistryName()); + Create.logger.debug("Prepared Redstone Network Space for " + world.getDimension().getType().getRegistryName()); } public void onUnloadWorld(IWorld world) { connections.remove(world); - Create.logger.debug("Removed Network Space for " + world.getDimension().getType().getRegistryName()); + Create.logger.debug("Removed Redstone Network Space for " + world.getDimension().getType().getRegistryName()); } private static Pair getNetworkKey(IHaveWireless actor) { diff --git a/src/main/resources/assets/create/textures/block/scarf.png b/src/main/resources/assets/create/textures/block/scarf.png new file mode 100644 index 000000000..ccb9dd313 Binary files /dev/null and b/src/main/resources/assets/create/textures/block/scarf.png differ diff --git a/src/main/resources/assets/create/textures/gui/filter.pdn b/src/main/resources/assets/create/textures/gui/filter.pdn new file mode 100644 index 000000000..02d317356 Binary files /dev/null and b/src/main/resources/assets/create/textures/gui/filter.pdn differ