mirror of
https://github.com/TicTicBoooom-Mods/MasterfulMachinery.git
synced 2026-03-18 21:40:34 +01:00
re-implementing create ports to incorporate stress units and more robust rotation
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.ticticboooom.mods.mm.block;
|
||||
|
||||
import com.ticticboooom.mods.mm.block.tile.IMachinePortTile;
|
||||
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
|
||||
import com.ticticboooom.mods.mm.inventory.ItemStackInventory;
|
||||
import lombok.Getter;
|
||||
@@ -62,8 +63,8 @@ public class MachinePortBlock extends Block {
|
||||
public ActionResultType onBlockActivated(BlockState state, World level, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult traceResult) {
|
||||
if (!level.isRemote()) {
|
||||
TileEntity blockEntity = level.getTileEntity(pos);
|
||||
if (blockEntity instanceof MachinePortBlockEntity) {
|
||||
NetworkHooks.openGui(((ServerPlayerEntity) player), (MachinePortBlockEntity)blockEntity, pos);
|
||||
if (blockEntity instanceof IMachinePortTile) {
|
||||
NetworkHooks.openGui(((ServerPlayerEntity) player), (IMachinePortTile)blockEntity, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,8 +94,8 @@ public class MachinePortBlock extends Block {
|
||||
public void neighborChanged(BlockState p_220069_1_, World world, BlockPos pos, Block p_220069_4_, BlockPos changedPos, boolean p_220069_6_) {
|
||||
super.neighborChanged(p_220069_1_, world, pos, p_220069_4_, changedPos, p_220069_6_);
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile instanceof MachinePortBlockEntity){
|
||||
((MachinePortBlockEntity) tile).getStorage().neighborChanged();
|
||||
if (tile instanceof IMachinePortTile){
|
||||
((IMachinePortTile) tile).getStorage().neighborChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.ticticboooom.mods.mm.block;
|
||||
|
||||
import com.simibubi.create.content.contraptions.base.IRotate;
|
||||
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
|
||||
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.StarlightPortStorage;
|
||||
import hellfirepvp.astralsorcery.common.block.base.BlockStarlightRecipient;
|
||||
import hellfirepvp.astralsorcery.common.constellation.IWeakConstellation;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class RotationMachinePortBlock extends MachinePortBlock implements IRotate {
|
||||
public RotationMachinePortBlock(RegistryObject<TileEntityType<?>> type, String name, String controllerId, String textureOverride, ResourceLocation overlay) {
|
||||
super(type, name, controllerId, textureOverride, overlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasShaftTowards(IWorldReader iWorldReader, BlockPos blockPos, BlockState blockState, Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction.Axis getRotationAxis(BlockState blockState) {
|
||||
return Direction.Axis.X;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.ticticboooom.mods.mm.block.container;
|
||||
|
||||
import com.ticticboooom.mods.mm.block.tile.ControllerBlockEntity;
|
||||
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
|
||||
import com.ticticboooom.mods.mm.block.tile.IMachinePortTile;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
@@ -18,9 +17,9 @@ public class PortBlockContainer extends Container {
|
||||
|
||||
private final PlayerInventory inv;
|
||||
@Getter
|
||||
private MachinePortBlockEntity tile;
|
||||
private IMachinePortTile tile;
|
||||
|
||||
public PortBlockContainer(@Nullable ContainerType<?> p_i50105_1_, int windowId, PlayerInventory inv, MachinePortBlockEntity tile) {
|
||||
public PortBlockContainer(@Nullable ContainerType<?> p_i50105_1_, int windowId, PlayerInventory inv, IMachinePortTile tile) {
|
||||
super(p_i50105_1_, windowId);
|
||||
this.inv = inv;
|
||||
tile.getStorage().setupContainer(this, inv, tile);
|
||||
@@ -28,7 +27,7 @@ public class PortBlockContainer extends Container {
|
||||
}
|
||||
|
||||
public PortBlockContainer(ContainerType<?> container, int windowId, PlayerInventory player, PacketBuffer buf) {
|
||||
this(container, windowId, player, (MachinePortBlockEntity) player.player.world.getTileEntity(buf.readBlockPos()));
|
||||
this(container, windowId, player, (IMachinePortTile) player.player.world.getTileEntity(buf.readBlockPos()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -69,8 +69,8 @@ public class ControllerBlockEntity extends UpdatableTile implements ITickableTil
|
||||
List<PortStorage> outputPorts = new ArrayList<>();
|
||||
for (BlockPos port : ports) {
|
||||
TileEntity blockEntity = world.getTileEntity(port);
|
||||
if (blockEntity instanceof MachinePortBlockEntity) {
|
||||
MachinePortBlockEntity portBE = (MachinePortBlockEntity) blockEntity;
|
||||
if (blockEntity instanceof IMachinePortTile) {
|
||||
IMachinePortTile portBE = (IMachinePortTile) blockEntity;
|
||||
|
||||
if (portBE.isInput()) {
|
||||
inputPorts.add(portBE.getStorage());
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.ticticboooom.mods.mm.block.tile;
|
||||
|
||||
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
|
||||
public interface IMachinePortTile extends INamedContainerProvider {
|
||||
PortStorage getStorage();
|
||||
boolean isInput();
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import vazkii.botania.api.mana.IManaReceiver;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class MachinePortBlockEntity extends UpdatableTile implements ITickableTileEntity, INamedContainerProvider {
|
||||
public class MachinePortBlockEntity extends UpdatableTile implements ITickableTileEntity, IMachinePortTile {
|
||||
|
||||
protected ContainerType<?> container;
|
||||
@Getter
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.ticticboooom.mods.mm.block.tile;
|
||||
|
||||
import com.simibubi.create.content.contraptions.KineticNetwork;
|
||||
import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||
import com.ticticboooom.mods.mm.block.container.PortBlockContainer;
|
||||
import com.ticticboooom.mods.mm.network.PacketHandler;
|
||||
import com.ticticboooom.mods.mm.network.packets.TileClientUpdatePacket;
|
||||
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.RotationPortStorage;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class RotationGenMachinePortBlockEntity extends GeneratingKineticTileEntity implements IMachinePortTile, ITickableTileEntity {
|
||||
private final ContainerType<?> container;
|
||||
@Getter
|
||||
private final PortStorage storage;
|
||||
@Getter
|
||||
private boolean input;
|
||||
|
||||
public RotationGenMachinePortBlockEntity(TileEntityType<?> typeIn, ContainerType<?> container, PortStorage storage, boolean input) {
|
||||
super(typeIn);
|
||||
this.container = container;
|
||||
this.storage = storage;
|
||||
this.input = input;
|
||||
if (input) {
|
||||
this.stress = ((RotationPortStorage) storage).getStress();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return new TranslationTextComponent("container.masterfulmachinery.create_rotation");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_) {
|
||||
return new PortBlockContainer(container, p_createMenu_1_, p_createMenu_2_, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (storage instanceof RotationPortStorage) {
|
||||
RotationPortStorage stor = (RotationPortStorage) this.storage;
|
||||
float speed = stor.getSpeed();
|
||||
if (speed != this.speed) {
|
||||
if (!hasSource()) {
|
||||
effects.queueRotationIndicators();
|
||||
}
|
||||
applyNewSpeed(this.speed, speed);
|
||||
}
|
||||
if (hasNetwork() && speed != 0) {
|
||||
KineticNetwork network = getOrCreateNetwork();
|
||||
notifyStressCapacityChange(calculateAddedStressCapacity());
|
||||
getOrCreateNetwork().updateCapacityFor(this, calculateStressApplied());
|
||||
network.updateStress();
|
||||
}
|
||||
|
||||
onSpeedChanged(this.speed);
|
||||
sendData();
|
||||
}
|
||||
|
||||
if (!world.isRemote()) {
|
||||
PacketHandler.INSTANCE.send(PacketDistributor.ALL.noArg(), new TileClientUpdatePacket.Data(pos, write(new CompoundNBT())));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fromTag(BlockState state, CompoundNBT compound, boolean clientPacket) {
|
||||
this.storage.load(compound.getCompound("inv"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(CompoundNBT compound, boolean clientPacket) {
|
||||
compound.put("inv", this.storage.save(new CompoundNBT()));
|
||||
super.write(compound, clientPacket);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getGeneratedSpeed() {
|
||||
if (storage instanceof RotationPortStorage) {
|
||||
RotationPortStorage stor = (RotationPortStorage) this.storage;
|
||||
return stor.getSpeed();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.ticticboooom.mods.mm.block.tile;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.content.contraptions.KineticNetwork;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||
import com.ticticboooom.mods.mm.block.container.PortBlockContainer;
|
||||
import com.ticticboooom.mods.mm.network.PacketHandler;
|
||||
import com.ticticboooom.mods.mm.network.packets.TileClientUpdatePacket;
|
||||
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.RotationPortStorage;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class RotationMachinePortBlockEntity extends KineticTileEntity implements IMachinePortTile, ITickableTileEntity {
|
||||
private final ContainerType<?> container;
|
||||
@Getter
|
||||
private final PortStorage storage;
|
||||
@Getter
|
||||
private boolean input;
|
||||
|
||||
public RotationMachinePortBlockEntity(TileEntityType<?> typeIn, ContainerType<?> container, PortStorage storage, boolean input) {
|
||||
super(typeIn);
|
||||
this.container = container;
|
||||
this.storage = storage;
|
||||
this.input = input;
|
||||
if (input) {
|
||||
this.stress = ((RotationPortStorage) storage).getStress();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return new TranslationTextComponent("container.masterfulmachinery.create_rotation");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_) {
|
||||
return new PortBlockContainer(container, p_createMenu_1_, p_createMenu_2_, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (this.world.isRemote) {
|
||||
return;
|
||||
}
|
||||
if (storage instanceof RotationPortStorage) {
|
||||
RotationPortStorage storage = (RotationPortStorage) this.storage;
|
||||
if (input) {
|
||||
storage.setSpeed(getSpeed());
|
||||
}
|
||||
}
|
||||
if (!world.isRemote()) {
|
||||
PacketHandler.INSTANCE.send(PacketDistributor.ALL.noArg(), new TileClientUpdatePacket.Data(pos, write(new CompoundNBT())));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fromTag(BlockState state, CompoundNBT compound, boolean clientPacket) {
|
||||
this.storage.load(compound.getCompound("inv"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(CompoundNBT compound, boolean clientPacket) {
|
||||
compound.put("inv", this.storage.save(new CompoundNBT()));
|
||||
super.write(compound, clientPacket);
|
||||
}
|
||||
}
|
||||
@@ -17,13 +17,13 @@ public class PortEnergyInventory implements IEnergyStorage {
|
||||
public int receiveEnergy(int maxReceive, boolean simulate) {
|
||||
if (simulate) {
|
||||
if ((long)maxReceive + stored > capacity) {
|
||||
return maxReceive - (stored + maxReceive - capacity);
|
||||
return (stored + maxReceive - capacity);
|
||||
} else {
|
||||
return maxReceive;
|
||||
}
|
||||
}
|
||||
if ((long)maxReceive + stored > capacity) {
|
||||
int result = maxReceive - (stored + maxReceive - capacity);
|
||||
int result = (stored + maxReceive - capacity);
|
||||
stored = capacity;
|
||||
return result;
|
||||
} else {
|
||||
|
||||
@@ -6,14 +6,25 @@ import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.DataResult;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.block.AstralMachinePortBlock;
|
||||
import com.ticticboooom.mods.mm.block.MachinePortBlock;
|
||||
import com.ticticboooom.mods.mm.block.RotationMachinePortBlock;
|
||||
import com.ticticboooom.mods.mm.block.tile.RotationGenMachinePortBlockEntity;
|
||||
import com.ticticboooom.mods.mm.block.tile.RotationMachinePortBlockEntity;
|
||||
import com.ticticboooom.mods.mm.ports.state.PortState;
|
||||
import com.ticticboooom.mods.mm.ports.state.RotationPortState;
|
||||
import com.ticticboooom.mods.mm.ports.storage.PortStorage;
|
||||
import com.ticticboooom.mods.mm.ports.storage.RotationPortStorage;
|
||||
import com.ticticboooom.mods.mm.registration.Registerable;
|
||||
import lombok.SneakyThrows;
|
||||
import mezz.jei.api.ingredients.IIngredients;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
@@ -22,8 +33,12 @@ public class RotationPortParser extends PortFactory {
|
||||
|
||||
@Override
|
||||
public Supplier<PortStorage> createStorage(JsonObject obj) {
|
||||
return RotationPortStorage::new;
|
||||
return () -> {
|
||||
DataResult<Pair<RotationPortStorage, JsonElement>> apply = JsonOps.INSTANCE.withDecoder(RotationPortStorage.CODEC).apply(obj);
|
||||
return apply.result().get().getFirst();
|
||||
};
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void write(PacketBuffer buf, PortState state) {
|
||||
@@ -55,4 +70,18 @@ public class RotationPortParser extends PortFactory {
|
||||
public PortState createState(PacketBuffer buf) {
|
||||
return buf.func_240628_a_(RotationPortState.CODEC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegistryObject<TileEntityType<?>> registerTileEntity(String id, DeferredRegister<TileEntityType<?>> reg, Registerable<RegistryObject<TileEntityType<?>>> tile, Registerable<RegistryObject<MachinePortBlock>> block, Registerable<RegistryObject<ContainerType<?>>> containerType, Supplier<PortStorage> portStorage, boolean isInput) {
|
||||
if (isInput) {
|
||||
return reg.register(id, () -> TileEntityType.Builder.create(() -> new RotationMachinePortBlockEntity(tile.get().get(), containerType.get().get(), portStorage.get(), isInput), block.get().get()).build(null));
|
||||
} else {
|
||||
return reg.register(id, () -> TileEntityType.Builder.create(() -> new RotationGenMachinePortBlockEntity(tile.get().get(), containerType.get().get(), portStorage.get(), isInput), block.get().get()).build(null));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegistryObject<MachinePortBlock> registerBlock(String id, DeferredRegister<Block> reg, Registerable<RegistryObject<TileEntityType<?>>> type, String name, String controllerId, String textureOverride, ResourceLocation overlay) {
|
||||
return reg.register(id, () -> new RotationMachinePortBlock(type.get(), name, controllerId, textureOverride, overlay));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import com.ticticboooom.mods.mm.MM;
|
||||
import com.ticticboooom.mods.mm.block.container.PortBlockContainer;
|
||||
import com.ticticboooom.mods.mm.block.tile.IMachinePortTile;
|
||||
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
|
||||
import com.ticticboooom.mods.mm.helper.InvHelper;
|
||||
import com.ticticboooom.mods.mm.inventory.ItemStackInventory;
|
||||
@@ -79,7 +80,7 @@ public class ItemPortStorage extends PortStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupContainer(PortBlockContainer container, PlayerInventory inv, MachinePortBlockEntity tile) {
|
||||
public void setupContainer(PortBlockContainer container, PlayerInventory inv, IMachinePortTile tile) {
|
||||
int offsetX = ((162 - (columns * 18)) / 2) + 8;
|
||||
int offsetY = ((108 - (rows * 18)) / 2) + 8;
|
||||
ItemStackInventory items = InvHelper.getItems(this.inv);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ticticboooom.mods.mm.ports.storage;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.ticticboooom.mods.mm.block.container.PortBlockContainer;
|
||||
import com.ticticboooom.mods.mm.block.tile.IMachinePortTile;
|
||||
import com.ticticboooom.mods.mm.block.tile.MachinePortBlockEntity;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
@@ -18,7 +19,7 @@ public abstract class PortStorage {
|
||||
public abstract CompoundNBT save(CompoundNBT nbt);
|
||||
public abstract void load(CompoundNBT nbt);
|
||||
public abstract void render(MatrixStack stack, int mouseX, int mouseY, int left, int top, Screen screen);
|
||||
public void setupContainer(PortBlockContainer container, PlayerInventory inv, MachinePortBlockEntity tile){
|
||||
public void setupContainer(PortBlockContainer container, PlayerInventory inv, IMachinePortTile tile){
|
||||
int playerOffsetX = 8;
|
||||
int playerOffsetY = 141;
|
||||
for (int j = 0; j < 3; j++) {
|
||||
|
||||
@@ -34,14 +34,23 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class RotationPortStorage extends PortStorage {
|
||||
|
||||
public static final Codec<RotationPortStorage> CODEC = RecordCodecBuilder.create(x -> x.group(
|
||||
Codec.INT.fieldOf("stress").forGetter(z -> z.stress)
|
||||
).apply(x, RotationPortStorage::new));
|
||||
@Getter
|
||||
@Setter
|
||||
private float speed;
|
||||
|
||||
@Getter
|
||||
private int stress;
|
||||
|
||||
public RotationPortStorage(int stress) {
|
||||
|
||||
this.stress = stress;
|
||||
}
|
||||
|
||||
private HashMap<Direction, KineticTileEntity> kinetics = new HashMap<>();
|
||||
public RotationPortStorage() {
|
||||
neighborChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,42 +83,5 @@ public class RotationPortStorage extends PortStorage {
|
||||
|
||||
@Override
|
||||
public void tick(MachinePortBlockEntity tile) {
|
||||
BlockPos blockPos = tile.getPos();
|
||||
World level = tile.getWorld();
|
||||
HashMap<Direction, TileEntity> tiles = new HashMap<>();
|
||||
tiles.put(Direction.EAST, level.getTileEntity(blockPos.add(1, 0, 0)));
|
||||
tiles.put(Direction.WEST, level.getTileEntity(blockPos.add(-1, 0, 0)));
|
||||
tiles.put(Direction.UP, level.getTileEntity(blockPos.add(0, 1, 0)));
|
||||
tiles.put(Direction.DOWN, level.getTileEntity(blockPos.add(0, -1, 0)));
|
||||
tiles.put(Direction.NORTH, level.getTileEntity(blockPos.add(0, 0, 1)));
|
||||
tiles.put(Direction.SOUTH, level.getTileEntity(blockPos.add(0, 0, -1)));
|
||||
speed = 0;
|
||||
if (tile.isInput()) {
|
||||
for (Map.Entry<Direction, TileEntity> tileEntity : tiles.entrySet()) {
|
||||
if (tileEntity.getValue() instanceof KineticTileEntity) {
|
||||
KineticTileEntity te = (KineticTileEntity) tileEntity.getValue();
|
||||
if (Math.abs(te.getSpeed()) > speed){
|
||||
speed = Math.abs(te.getSpeed());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (Map.Entry<Direction, TileEntity> tileEntity : tiles.entrySet()) {
|
||||
if (tileEntity.getValue() instanceof KineticTileEntity) {
|
||||
|
||||
KineticTileEntity te = (KineticTileEntity) tileEntity.getValue();
|
||||
if (speed == 0){
|
||||
te.detachKinetics();
|
||||
te.setSpeed(0);
|
||||
te.setNetwork(null);
|
||||
} else {
|
||||
te.setSpeed(speed);
|
||||
te.setNetwork(te.getPos().toLong());
|
||||
te.attachKinetics();
|
||||
}
|
||||
te.notifyUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#Mon May 24 20:28:48 BST 2021
|
||||
VERSION_CODE=86
|
||||
#Tue May 25 00:48:05 BST 2021
|
||||
VERSION_CODE=154
|
||||
|
||||
Reference in New Issue
Block a user