From 22fc9d1100202dad7d3b406121af0dc1e824b941 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue, 27 Aug 2019 17:35:34 +0200 Subject: [PATCH] Logistics Part III - Fixed Redstone bridges activating inconsistently - Fixed Redstone bridges breaking on world reload - Completed the Stockpile Switch - Added Skeleton for filters - Added Skeleton for extractors - Renamed some stuff --- .../java/com/simibubi/create/AllBlocks.java | 12 +- .../com/simibubi/create/AllContainers.java | 8 +- .../java/com/simibubi/create/AllItems.java | 8 + .../java/com/simibubi/create/AllPackets.java | 4 + .../com/simibubi/create/AllTileEntities.java | 10 +- src/main/java/com/simibubi/create/Create.java | 1 + .../foundation/block/SyncedTileEntity.java | 26 ++- .../create/foundation/gui/widgets/Label.java | 3 + .../packet/TileEntityConfigurationPacket.java | 57 +++++ .../foundation/utility/ContainerListener.java | 7 + .../contraptions/RotationPropagator.java | 8 +- .../contraptions/base/KineticTileEntity.java | 4 - .../generators/WaterWheelTileEntity.java | 2 +- .../MechanicalPistonTileEntity.java | 4 +- .../{shopping => economy}/ShopShelfBlock.java | 2 +- .../ShopShelfContainer.java | 2 +- .../ShopShelfScreen.java | 2 +- .../ShopShelfTileEntity.java | 4 +- .../modules/logistics/FlexCrateBlock.java | 85 -------- .../modules/logistics/FlexCrateContainer.java | 79 ------- .../modules/logistics/FlexCrateScreen.java | 93 -------- .../logistics/FlexCrateTileEntity.java | 104 --------- .../modules/logistics/FrequencyHandler.java | 131 ++++++++++++ .../modules/logistics/IHaveWireless.java | 19 ++ .../modules/logistics/IReceiveWireless.java | 7 + .../modules/logistics/ITransmitWireless.java | 10 + .../logistics/RedstoneBridgeTileEntity.java | 199 ------------------ .../logistics/StockswitchTileEntity.java | 48 ----- .../logistics/block/ExtractorBlock.java | 78 +++++++ .../logistics/{ => block}/FlexcrateBlock.java | 2 +- .../{ => block}/FlexcrateContainer.java | 6 +- .../{ => block}/FlexcrateScreen.java | 15 +- .../{ => block}/FlexcrateTileEntity.java | 21 +- .../logistics/block/LinkedExtractorBlock.java | 31 +++ .../{ => block}/RedstoneBridgeBlock.java | 63 +++--- .../block/RedstoneBridgeTileEntity.java | 135 ++++++++++++ .../RedstoneBridgeTileEntityRenderer.java | 2 +- .../{ => block}/StockswitchBlock.java | 45 +++- .../{ => block}/StockswitchScreen.java | 43 +++- .../block/StockswitchTileEntity.java | 130 ++++++++++++ .../modules/logistics/item/FilterItem.java | 38 ++++ .../packet/ConfigureFlexcratePacket.java | 37 ++++ .../packet/ConfigureStockswitchPacket.java | 42 ++++ .../assets/create/blockstates/extractor.json | 18 ++ .../create/blockstates/linked_extractor.json | 18 ++ .../resources/assets/create/lang/en_us.json | 3 + .../assets/create/models/block/extractor.json | 75 +++++++ .../models/block/extractor_powered.json | 7 + .../models/block/extractor_wireless.json | 112 ++++++++++ .../block/extractor_wireless_powered.json | 8 + .../create/models/block/stockpile_switch.json | 3 +- .../assets/create/models/item/extractor.json | 10 + .../assets/create/models/item/filter.json | 8 + .../create/models/item/linked_extractor.json | 10 + .../assets/create/models/item/shop_shelf.json | 9 +- .../create/textures/block/extractor.png | Bin 0 -> 491 bytes .../textures/block/extractor_powered.png | Bin 0 -> 509 bytes .../textures/block/stockpile_switch_end.png | Bin 0 -> 364 bytes .../assets/create/textures/item/filter.png | Bin 0 -> 278 bytes .../assets/create/textures/item/filter_1.png | Bin 0 -> 164 bytes .../assets/create/textures/item/filter_2.png | Bin 0 -> 173 bytes 61 files changed, 1206 insertions(+), 702 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/packet/TileEntityConfigurationPacket.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/ContainerListener.java rename src/main/java/com/simibubi/create/modules/{shopping => economy}/ShopShelfBlock.java (98%) rename src/main/java/com/simibubi/create/modules/{shopping => economy}/ShopShelfContainer.java (93%) rename src/main/java/com/simibubi/create/modules/{shopping => economy}/ShopShelfScreen.java (91%) rename src/main/java/com/simibubi/create/modules/{shopping => economy}/ShopShelfTileEntity.java (94%) delete mode 100644 src/main/java/com/simibubi/create/modules/logistics/FlexCrateBlock.java delete mode 100644 src/main/java/com/simibubi/create/modules/logistics/FlexCrateContainer.java delete mode 100644 src/main/java/com/simibubi/create/modules/logistics/FlexCrateScreen.java delete mode 100644 src/main/java/com/simibubi/create/modules/logistics/FlexCrateTileEntity.java create mode 100644 src/main/java/com/simibubi/create/modules/logistics/FrequencyHandler.java create mode 100644 src/main/java/com/simibubi/create/modules/logistics/IHaveWireless.java create mode 100644 src/main/java/com/simibubi/create/modules/logistics/IReceiveWireless.java create mode 100644 src/main/java/com/simibubi/create/modules/logistics/ITransmitWireless.java delete mode 100644 src/main/java/com/simibubi/create/modules/logistics/RedstoneBridgeTileEntity.java delete mode 100644 src/main/java/com/simibubi/create/modules/logistics/StockswitchTileEntity.java create mode 100644 src/main/java/com/simibubi/create/modules/logistics/block/ExtractorBlock.java rename src/main/java/com/simibubi/create/modules/logistics/{ => block}/FlexcrateBlock.java (98%) rename src/main/java/com/simibubi/create/modules/logistics/{ => block}/FlexcrateContainer.java (94%) rename src/main/java/com/simibubi/create/modules/logistics/{ => block}/FlexcrateScreen.java (88%) rename src/main/java/com/simibubi/create/modules/logistics/{ => block}/FlexcrateTileEntity.java (86%) create mode 100644 src/main/java/com/simibubi/create/modules/logistics/block/LinkedExtractorBlock.java rename src/main/java/com/simibubi/create/modules/logistics/{ => block}/RedstoneBridgeBlock.java (90%) create mode 100644 src/main/java/com/simibubi/create/modules/logistics/block/RedstoneBridgeTileEntity.java rename src/main/java/com/simibubi/create/modules/logistics/{ => block}/RedstoneBridgeTileEntityRenderer.java (98%) rename src/main/java/com/simibubi/create/modules/logistics/{ => block}/StockswitchBlock.java (70%) rename src/main/java/com/simibubi/create/modules/logistics/{ => block}/StockswitchScreen.java (75%) create mode 100644 src/main/java/com/simibubi/create/modules/logistics/block/StockswitchTileEntity.java create mode 100644 src/main/java/com/simibubi/create/modules/logistics/item/FilterItem.java create mode 100644 src/main/java/com/simibubi/create/modules/logistics/packet/ConfigureFlexcratePacket.java create mode 100644 src/main/java/com/simibubi/create/modules/logistics/packet/ConfigureStockswitchPacket.java create mode 100644 src/main/resources/assets/create/blockstates/extractor.json create mode 100644 src/main/resources/assets/create/blockstates/linked_extractor.json create mode 100644 src/main/resources/assets/create/models/block/extractor.json create mode 100644 src/main/resources/assets/create/models/block/extractor_powered.json create mode 100644 src/main/resources/assets/create/models/block/extractor_wireless.json create mode 100644 src/main/resources/assets/create/models/block/extractor_wireless_powered.json create mode 100644 src/main/resources/assets/create/models/item/extractor.json create mode 100644 src/main/resources/assets/create/models/item/filter.json create mode 100644 src/main/resources/assets/create/models/item/linked_extractor.json create mode 100644 src/main/resources/assets/create/textures/block/extractor.png create mode 100644 src/main/resources/assets/create/textures/block/extractor_powered.png create mode 100644 src/main/resources/assets/create/textures/block/stockpile_switch_end.png create mode 100644 src/main/resources/assets/create/textures/item/filter.png create mode 100644 src/main/resources/assets/create/textures/item/filter_1.png create mode 100644 src/main/resources/assets/create/textures/item/filter_2.png diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index 83b8afc25..8703cb967 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -24,14 +24,16 @@ import com.simibubi.create.modules.contraptions.relays.CogWheelBlock; import com.simibubi.create.modules.contraptions.relays.EncasedBeltBlock; import com.simibubi.create.modules.contraptions.relays.GearboxBlock; import com.simibubi.create.modules.contraptions.relays.GearshifterBlock; +import com.simibubi.create.modules.economy.ShopShelfBlock; import com.simibubi.create.modules.gardens.CocoaLogBlock; -import com.simibubi.create.modules.logistics.FlexcrateBlock; -import com.simibubi.create.modules.logistics.RedstoneBridgeBlock; -import com.simibubi.create.modules.logistics.StockswitchBlock; +import com.simibubi.create.modules.logistics.block.ExtractorBlock; +import com.simibubi.create.modules.logistics.block.FlexcrateBlock; +import com.simibubi.create.modules.logistics.block.LinkedExtractorBlock; +import com.simibubi.create.modules.logistics.block.RedstoneBridgeBlock; +import com.simibubi.create.modules.logistics.block.StockswitchBlock; import com.simibubi.create.modules.schematics.block.CreativeCrateBlock; import com.simibubi.create.modules.schematics.block.SchematicTableBlock; import com.simibubi.create.modules.schematics.block.SchematicannonBlock; -import com.simibubi.create.modules.shopping.ShopShelfBlock; import com.simibubi.create.modules.symmetry.block.CrossPlaneSymmetryBlock; import com.simibubi.create.modules.symmetry.block.PlaneSymmetryBlock; import com.simibubi.create.modules.symmetry.block.TriplePlaneSymmetryBlock; @@ -94,6 +96,8 @@ public enum AllBlocks { REDSTONE_BRIDGE(new RedstoneBridgeBlock()), STOCKSWITCH(new StockswitchBlock()), FLEXCRATE(new FlexcrateBlock()), + EXTRACTOR(new ExtractorBlock()), + LINKED_EXTRACTOR(new LinkedExtractorBlock()), // Symmetry SYMMETRY_PLANE(new PlaneSymmetryBlock()), diff --git a/src/main/java/com/simibubi/create/AllContainers.java b/src/main/java/com/simibubi/create/AllContainers.java index e32f8d873..203741c58 100644 --- a/src/main/java/com/simibubi/create/AllContainers.java +++ b/src/main/java/com/simibubi/create/AllContainers.java @@ -1,13 +1,13 @@ package com.simibubi.create; -import com.simibubi.create.modules.logistics.FlexcrateContainer; -import com.simibubi.create.modules.logistics.FlexcrateScreen; +import com.simibubi.create.modules.economy.ShopShelfContainer; +import com.simibubi.create.modules.economy.ShopShelfScreen; +import com.simibubi.create.modules.logistics.block.FlexcrateContainer; +import com.simibubi.create.modules.logistics.block.FlexcrateScreen; import com.simibubi.create.modules.schematics.block.SchematicTableContainer; import com.simibubi.create.modules.schematics.block.SchematicTableScreen; import com.simibubi.create.modules.schematics.block.SchematicannonContainer; import com.simibubi.create.modules.schematics.block.SchematicannonScreen; -import com.simibubi.create.modules.shopping.ShopShelfContainer; -import com.simibubi.create.modules.shopping.ShopShelfScreen; import net.minecraft.client.gui.IHasContainer; import net.minecraft.client.gui.ScreenManager; diff --git a/src/main/java/com/simibubi/create/AllItems.java b/src/main/java/com/simibubi/create/AllItems.java index 54a6acb68..8c5ec7cc1 100644 --- a/src/main/java/com/simibubi/create/AllItems.java +++ b/src/main/java/com/simibubi/create/AllItems.java @@ -5,12 +5,14 @@ import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunItem; import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunItemRenderer; import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunModel; import com.simibubi.create.modules.gardens.TreeFertilizerItem; +import com.simibubi.create.modules.logistics.item.FilterItem; import com.simibubi.create.modules.schematics.item.BlueprintAndQuillItem; import com.simibubi.create.modules.schematics.item.BlueprintItem; import com.simibubi.create.modules.symmetry.SymmetryWandItem; import com.simibubi.create.modules.symmetry.client.SymmetryWandItemRenderer; import com.simibubi.create.modules.symmetry.client.SymmetryWandModel; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.ModelResourceLocation; import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer; @@ -45,6 +47,7 @@ public enum AllItems { BLUEPRINT_AND_QUILL(new BlueprintAndQuillItem(standardProperties().maxStackSize(1))), BLUEPRINT(new BlueprintItem(standardProperties())), BELT_CONNECTOR(new BeltItem(standardProperties())), + FILTER(new FilterItem(standardProperties())), ; @@ -81,6 +84,11 @@ public enum AllItems { SYMMETRY_WAND, BUILDER_GUN,; } + @OnlyIn(Dist.CLIENT) + public static void registerColorHandlers() { + Minecraft.getInstance().getItemColors().register(new FilterItem.Color(), FILTER.item); + } + @OnlyIn(Dist.CLIENT) public static ItemStackTileEntityRenderer renderUsing(AllItemRenderers renderer) { switch (renderer) { diff --git a/src/main/java/com/simibubi/create/AllPackets.java b/src/main/java/com/simibubi/create/AllPackets.java index e2f7f9e64..2109b55e6 100644 --- a/src/main/java/com/simibubi/create/AllPackets.java +++ b/src/main/java/com/simibubi/create/AllPackets.java @@ -7,6 +7,8 @@ import java.util.function.Supplier; import com.simibubi.create.foundation.packet.NbtPacket; import com.simibubi.create.foundation.packet.SimplePacketBase; import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunBeamPacket; +import com.simibubi.create.modules.logistics.packet.ConfigureFlexcratePacket; +import com.simibubi.create.modules.logistics.packet.ConfigureStockswitchPacket; import com.simibubi.create.modules.schematics.packet.ConfigureSchematicannonPacket; import com.simibubi.create.modules.schematics.packet.SchematicPlacePacket; import com.simibubi.create.modules.schematics.packet.SchematicUploadPacket; @@ -23,6 +25,8 @@ public enum AllPackets { // Client to Server NBT(NbtPacket.class, NbtPacket::new), CONFIGURE_SCHEMATICANNON(ConfigureSchematicannonPacket.class, ConfigureSchematicannonPacket::new), + CONFIGURE_FLEXCRATE(ConfigureFlexcratePacket.class, ConfigureFlexcratePacket::new), + CONFIGURE_STOCKSWITCH(ConfigureStockswitchPacket.class, ConfigureStockswitchPacket::new), PLACE_SCHEMATIC(SchematicPlacePacket.class, SchematicPlacePacket::new), UPLOAD_SCHEMATIC(SchematicUploadPacket.class, SchematicUploadPacket::new), diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 0f2eed3e2..1df016a73 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -21,14 +21,14 @@ import com.simibubi.create.modules.contraptions.relays.GearboxTileEntity; import com.simibubi.create.modules.contraptions.relays.GearboxTileEntityRenderer; import com.simibubi.create.modules.contraptions.relays.GearshifterTileEntity; import com.simibubi.create.modules.contraptions.relays.GearshifterTileEntityRenderer; -import com.simibubi.create.modules.logistics.FlexcrateTileEntity; -import com.simibubi.create.modules.logistics.RedstoneBridgeTileEntity; -import com.simibubi.create.modules.logistics.RedstoneBridgeTileEntityRenderer; -import com.simibubi.create.modules.logistics.StockswitchTileEntity; +import com.simibubi.create.modules.economy.ShopShelfTileEntity; +import com.simibubi.create.modules.logistics.block.FlexcrateTileEntity; +import com.simibubi.create.modules.logistics.block.RedstoneBridgeTileEntity; +import com.simibubi.create.modules.logistics.block.RedstoneBridgeTileEntityRenderer; +import com.simibubi.create.modules.logistics.block.StockswitchTileEntity; import com.simibubi.create.modules.schematics.block.SchematicTableTileEntity; import com.simibubi.create.modules.schematics.block.SchematicannonRenderer; import com.simibubi.create.modules.schematics.block.SchematicannonTileEntity; -import com.simibubi.create.modules.shopping.ShopShelfTileEntity; import net.minecraft.block.Block; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index fc4b52825..b21129fdc 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -66,6 +66,7 @@ public class Create { ScrollFixer.init(); TOOL_MENU = new KeyBinding("Tool Menu (Hold)", KeyboardHelper.LALT, NAME); ClientRegistry.registerKeyBinding(TOOL_MENU); + AllItems.registerColorHandlers(); }); } diff --git a/src/main/java/com/simibubi/create/foundation/block/SyncedTileEntity.java b/src/main/java/com/simibubi/create/foundation/block/SyncedTileEntity.java index 3402175d1..2fe20f40d 100644 --- a/src/main/java/com/simibubi/create/foundation/block/SyncedTileEntity.java +++ b/src/main/java/com/simibubi/create/foundation/block/SyncedTileEntity.java @@ -11,37 +11,45 @@ public abstract class SyncedTileEntity extends TileEntity { public SyncedTileEntity(TileEntityType tileEntityTypeIn) { super(tileEntityTypeIn); } - + @Override public CompoundNBT getTileData() { return super.getTileData(); } - + @Override public CompoundNBT getUpdateTag() { return write(new CompoundNBT()); } - + @Override public void handleUpdateTag(CompoundNBT tag) { read(tag); } + + public void sendData() { + world.notifyBlockUpdate(getPos(), getBlockState(), getBlockState(), 2 | 16); + } - @Override - public SUpdateTileEntityPacket getUpdatePacket(){ - return new SUpdateTileEntityPacket(getPos(), 1, writeToClient(new CompoundNBT())); + public void causeBlockUpdate() { + world.notifyBlockUpdate(getPos(), getBlockState(), getBlockState(), 1); } @Override - public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt){ + public SUpdateTileEntityPacket getUpdatePacket() { + return new SUpdateTileEntityPacket(getPos(), 1, writeToClient(new CompoundNBT())); + } + + @Override + public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) { readClientUpdate(pkt.getNbtCompound()); } - + // Special handling for client update packets public void readClientUpdate(CompoundNBT tag) { read(tag); } - + // Special handling for client update packets public CompoundNBT writeToClient(CompoundNBT tag) { return write(tag); diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/Label.java b/src/main/java/com/simibubi/create/foundation/gui/widgets/Label.java index 945e5cd6a..3d58e5dac 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/Label.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widgets/Label.java @@ -1,5 +1,7 @@ package com.simibubi.create.foundation.gui.widgets; +import com.mojang.blaze3d.platform.GlStateManager; + import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; @@ -42,6 +44,7 @@ public class Label extends AbstractSimiWidget { if (text == null || text.isEmpty()) return; + GlStateManager.color4f(1, 1, 1, 1); if (hasShadow) font.drawStringWithShadow(text + suffix, x, y, color); else diff --git a/src/main/java/com/simibubi/create/foundation/packet/TileEntityConfigurationPacket.java b/src/main/java/com/simibubi/create/foundation/packet/TileEntityConfigurationPacket.java new file mode 100644 index 000000000..7acd40bb5 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/packet/TileEntityConfigurationPacket.java @@ -0,0 +1,57 @@ +package com.simibubi.create.foundation.packet; + +import java.util.function.Supplier; + +import com.simibubi.create.foundation.block.SyncedTileEntity; + +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.network.PacketBuffer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.network.NetworkEvent.Context; + +public abstract class TileEntityConfigurationPacket extends SimplePacketBase { + + protected BlockPos pos; + + public TileEntityConfigurationPacket(PacketBuffer buffer) { + pos = buffer.readBlockPos(); + readSettings(buffer); + } + + public TileEntityConfigurationPacket(BlockPos pos) { + this.pos = pos; + } + + @Override + public void write(PacketBuffer buffer) { + buffer.writeBlockPos(pos); + writeSettings(buffer); + } + + @SuppressWarnings("unchecked") + @Override + public void handle(Supplier context) { + context.get().enqueueWork(() -> { + ServerPlayerEntity player = context.get().getSender(); + World world = player.world; + + if (world == null || world.getTileEntity(pos) == null) + return; + TileEntity tileEntity = world.getTileEntity(pos); + if (tileEntity instanceof SyncedTileEntity) { + applySettings((TE) tileEntity); + ((SyncedTileEntity) tileEntity).sendData(); + tileEntity.markDirty(); + } + }); + context.get().setPacketHandled(true); + + } + + protected abstract void writeSettings(PacketBuffer buffer); + protected abstract void readSettings(PacketBuffer buffer); + protected abstract void applySettings(TE te); + +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/ContainerListener.java b/src/main/java/com/simibubi/create/foundation/utility/ContainerListener.java new file mode 100644 index 000000000..617471b7b --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/ContainerListener.java @@ -0,0 +1,7 @@ +package com.simibubi.create.foundation.utility; + +public class ContainerListener { + + + +} 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 66c0b6af5..5fb3472ce 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java @@ -143,14 +143,14 @@ public class RotationPropagator { if (neighbourTE.hasSource() && neighbourTE.getSource().equals(addedTE.getPos())) { addedTE.setSpeed(neighbourTE.getSpeed() * speedModifier); addedTE.onSpeedChanged(); - addedTE.notifyBlockUpdate(); + addedTE.sendData(); continue; } addedTE.setSpeed(neighbourTE.getSpeed() * speedModifier); addedTE.setSource(neighbourTE.getPos()); addedTE.onSpeedChanged(); - addedTE.notifyBlockUpdate(); + addedTE.sendData(); propagateNewSource(addedTE); return; } @@ -183,7 +183,7 @@ public class RotationPropagator { neighbourTE.setSpeed(newSpeed); neighbourTE.setSource(updateTE.getPos()); neighbourTE.onSpeedChanged(); - neighbourTE.notifyBlockUpdate(); + neighbourTE.sendData(); propagateNewSource(neighbourTE); } @@ -234,7 +234,7 @@ public class RotationPropagator { final KineticTileEntity currentTE = (KineticTileEntity) world.getTileEntity(pos); currentTE.removeSource(); - currentTE.notifyBlockUpdate(); + currentTE.sendData(); for (KineticTileEntity neighbourTE : getConnectedNeighbours(currentTE)) { if (neighbourTE.isSource()) { 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 0b4ef136f..c3d531ef6 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 @@ -51,10 +51,6 @@ public abstract class KineticTileEntity extends SyncedTileEntity { super.remove(); } - public void notifyBlockUpdate() { - this.world.notifyBlockUpdate(getPos(), getBlockState(), getBlockState(), 2 | 16); - } - @Override public CompoundNBT write(CompoundNBT compound) { compound.putFloat("Speed", getSpeed()); 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 aa3873d37..07437a2b2 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 @@ -62,7 +62,7 @@ public class WaterWheelTileEntity extends KineticTileEntity { RotationPropagator.handleRemoved(world, pos, this); this.setSpeed(speed); hasFlows = speed != 0; - notifyBlockUpdate(); + sendData(); RotationPropagator.handleAdded(world, pos, this); } 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 d23bad29b..c07845798 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 @@ -109,7 +109,7 @@ public class MechanicalPistonTileEntity extends KineticTileEntity implements ITi offset = movingConstruct.initialExtensionProgress; movingPistons.add(this); - notifyBlockUpdate(); + sendData(); getWorld().setBlockState(pos, getBlockState().with(MechanicalPistonBlock.STATE, PistonState.MOVING), 66); for (BlockInfo block : movingConstruct.blocks.values()) { BlockPos startPos = block.pos.offset(direction, movingConstruct.initialExtensionProgress); @@ -148,7 +148,7 @@ public class MechanicalPistonTileEntity extends KineticTileEntity implements ITi running = false; movingPistons.remove(this); movingConstruct = null; - notifyBlockUpdate(); + sendData(); } @Override diff --git a/src/main/java/com/simibubi/create/modules/shopping/ShopShelfBlock.java b/src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java similarity index 98% rename from src/main/java/com/simibubi/create/modules/shopping/ShopShelfBlock.java rename to src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java index 485fb8640..2cf1aa981 100644 --- a/src/main/java/com/simibubi/create/modules/shopping/ShopShelfBlock.java +++ b/src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.shopping; +package com.simibubi.create.modules.economy; import net.minecraft.block.Block; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/modules/shopping/ShopShelfContainer.java b/src/main/java/com/simibubi/create/modules/economy/ShopShelfContainer.java similarity index 93% rename from src/main/java/com/simibubi/create/modules/shopping/ShopShelfContainer.java rename to src/main/java/com/simibubi/create/modules/economy/ShopShelfContainer.java index 5f4619cbb..c683cd2ad 100644 --- a/src/main/java/com/simibubi/create/modules/shopping/ShopShelfContainer.java +++ b/src/main/java/com/simibubi/create/modules/economy/ShopShelfContainer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.shopping; +package com.simibubi.create.modules.economy; import com.simibubi.create.AllContainers; diff --git a/src/main/java/com/simibubi/create/modules/shopping/ShopShelfScreen.java b/src/main/java/com/simibubi/create/modules/economy/ShopShelfScreen.java similarity index 91% rename from src/main/java/com/simibubi/create/modules/shopping/ShopShelfScreen.java rename to src/main/java/com/simibubi/create/modules/economy/ShopShelfScreen.java index 58b92b31a..93bbe3188 100644 --- a/src/main/java/com/simibubi/create/modules/shopping/ShopShelfScreen.java +++ b/src/main/java/com/simibubi/create/modules/economy/ShopShelfScreen.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.shopping; +package com.simibubi.create.modules.economy; import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; diff --git a/src/main/java/com/simibubi/create/modules/shopping/ShopShelfTileEntity.java b/src/main/java/com/simibubi/create/modules/economy/ShopShelfTileEntity.java similarity index 94% rename from src/main/java/com/simibubi/create/modules/shopping/ShopShelfTileEntity.java rename to src/main/java/com/simibubi/create/modules/economy/ShopShelfTileEntity.java index 21f8cf322..54e2a70c7 100644 --- a/src/main/java/com/simibubi/create/modules/shopping/ShopShelfTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/economy/ShopShelfTileEntity.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.shopping; +package com.simibubi.create.modules.economy; import java.util.UUID; @@ -20,7 +20,7 @@ public class ShopShelfTileEntity extends SyncedTileEntity implements INamedConta private UUID owner; public ShopShelfTileEntity() { - super(AllTileEntities.ShopShelfTileEntity.type); + super(AllTileEntities.SHOP_SHELF.type); } @Override diff --git a/src/main/java/com/simibubi/create/modules/logistics/FlexCrateBlock.java b/src/main/java/com/simibubi/create/modules/logistics/FlexCrateBlock.java deleted file mode 100644 index fba8e41a2..000000000 --- a/src/main/java/com/simibubi/create/modules/logistics/FlexCrateBlock.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.simibubi.create.modules.logistics; - -import com.simibubi.create.foundation.block.InfoBlock; -import com.simibubi.create.foundation.utility.ItemDescription; -import com.simibubi.create.foundation.utility.ItemDescription.Palette; - -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.inventory.InventoryHelper; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.shapes.ISelectionContext; -import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.World; -import net.minecraftforge.fml.network.NetworkHooks; - -public class FlexcrateBlock extends InfoBlock { - - public static final VoxelShape SHAPE = makeCuboidShape(1, 0, 1, 15, 14, 15); - - public FlexcrateBlock() { - super(Properties.from(Blocks.ANDESITE)); - } - - @Override - public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return SHAPE; - } - - @Override - public boolean hasTileEntity(BlockState state) { - return true; - } - - @Override - public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, - BlockRayTraceResult hit) { - - if (worldIn.isRemote) { - return true; - } else { - FlexcrateTileEntity te = (FlexcrateTileEntity) worldIn.getTileEntity(pos); - if (te != null) - NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer); - return true; - } - } - - @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { - return new FlexcrateTileEntity(); - } - - @Override - public ItemDescription getDescription() { - Palette color = Palette.Yellow; - return new ItemDescription(color) - .withSummary("This Storage Container allows Manual control over its capacity. It can hold up to " - + h("16 Stacks", color) + " of Items.") - .createTabs(); - } - - @Override - public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { - if (worldIn.getTileEntity(pos) == null) - return; - - FlexcrateTileEntity te = (FlexcrateTileEntity) worldIn.getTileEntity(pos); - for (int slot = 0; slot < te.inventory.getSlots(); slot++) { - InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), - te.inventory.getStackInSlot(slot)); - } - - if (state.hasTileEntity() && state.getBlock() != newState.getBlock()) { - worldIn.removeTileEntity(pos); - } - - } - -} diff --git a/src/main/java/com/simibubi/create/modules/logistics/FlexCrateContainer.java b/src/main/java/com/simibubi/create/modules/logistics/FlexCrateContainer.java deleted file mode 100644 index 82c1ec111..000000000 --- a/src/main/java/com/simibubi/create/modules/logistics/FlexCrateContainer.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.simibubi.create.modules.logistics; - -import com.simibubi.create.AllContainers; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.network.PacketBuffer; -import net.minecraftforge.items.SlotItemHandler; - -public class FlexcrateContainer extends Container { - - public FlexcrateTileEntity te; - public PlayerInventory playerInventory; - - public FlexcrateContainer(int id, PlayerInventory inv, PacketBuffer extraData) { - super(AllContainers.FlexCrate.type, id); - ClientWorld world = Minecraft.getInstance().world; - this.te = (FlexcrateTileEntity) world.getTileEntity(extraData.readBlockPos()); - this.te.handleUpdateTag(extraData.readCompoundTag()); - this.playerInventory = inv; - init(); - } - - public FlexcrateContainer(int id, PlayerInventory inv, FlexcrateTileEntity te) { - super(AllContainers.FlexCrate.type, id); - this.te = te; - this.playerInventory = inv; - init(); - } - - private void init() { - for (int row = 0; row < 4; ++row) { - for (int col = 0; col < 4; ++col) { - this.addSlot(new SlotItemHandler(te.inventory, col + row * 4, 124 + col * 18, 25 + row * 18)); - } - } - - // player Slots - int xOffset = 58; - int yOffset = 157; - for (int row = 0; row < 3; ++row) { - for (int col = 0; col < 9; ++col) { - this.addSlot(new Slot(playerInventory, col + row * 9 + 9, xOffset + col * 18, yOffset + row * 18)); - } - } - - for (int hotbarSlot = 0; hotbarSlot < 9; ++hotbarSlot) { - this.addSlot(new Slot(playerInventory, hotbarSlot, xOffset + hotbarSlot * 18, yOffset + 58)); - } - - detectAndSendChanges(); - } - - @Override - public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) { - Slot clickedSlot = getSlot(index); - if (!clickedSlot.getHasStack()) - return ItemStack.EMPTY; - - ItemStack stack = clickedSlot.getStack(); - if (index < 16) - mergeItemStack(stack, 16, inventorySlots.size(), false); - else - mergeItemStack(stack, 0, 15, false); - - return ItemStack.EMPTY; - } - - @Override - public boolean canInteractWith(PlayerEntity playerIn) { - return true; - } - -} diff --git a/src/main/java/com/simibubi/create/modules/logistics/FlexCrateScreen.java b/src/main/java/com/simibubi/create/modules/logistics/FlexCrateScreen.java deleted file mode 100644 index cf2fb3ace..000000000 --- a/src/main/java/com/simibubi/create/modules/logistics/FlexCrateScreen.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.simibubi.create.modules.logistics; - -import static com.simibubi.create.foundation.gui.ScreenResources.FLEXCRATE; -import static com.simibubi.create.foundation.gui.ScreenResources.PLAYER_INVENTORY; - -import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.AllBlocks; -import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; -import com.simibubi.create.foundation.gui.ScreenElementRenderer; -import com.simibubi.create.foundation.gui.ScreenResources; -import com.simibubi.create.foundation.gui.widgets.Label; -import com.simibubi.create.foundation.gui.widgets.ScrollInput; - -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.util.text.ITextComponent; - -public class FlexcrateScreen extends AbstractSimiContainerScreen { - - private FlexcrateTileEntity te; - private Label allowedItemsLabel; - private ScrollInput allowedItems; - private int lastModification; - - public FlexcrateScreen(FlexcrateContainer container, PlayerInventory inv, ITextComponent title) { - super(container, inv, title); - te = container.te; - lastModification = -1; - } - - @Override - protected void init() { - setWindowSize(PLAYER_INVENTORY.width + 100, FLEXCRATE.height + PLAYER_INVENTORY.height + 20); - super.init(); - widgets.clear(); - - allowedItemsLabel = new Label(guiLeft + 100 + 70, guiTop + 107, "").colored(0xD3CBBE).withShadow(); - allowedItems = new ScrollInput(guiLeft + 100 + 65, guiTop + 104, 41, 14).titled("Storage Space") - .withRange(1, 1025).writingTo(allowedItemsLabel).withShiftStep(64).setState(te.allowedAmount) - .calling(s -> lastModification = 0); - allowedItems.onChanged(); - widgets.add(allowedItemsLabel); - widgets.add(allowedItems); - } - - @Override - protected void renderWindow(int mouseX, int mouseY, float partialTicks) { - int crateLeft = guiLeft + 100; - int crateTop = guiTop; - int invLeft = guiLeft + 50; - int invTop = crateTop + FLEXCRATE.height + 10; - int hFontColor = 0xD3CBBE; - int fontColor = 0x4B3A22; - - FLEXCRATE.draw(this, crateLeft, crateTop); - font.drawStringWithShadow("FlexCrate", crateLeft - 3 + (FLEXCRATE.width - font.getStringWidth("FlexCrate")) / 2, - crateTop + 10, hFontColor); - String itemCount = "" + te.itemCount; - font.drawString(itemCount, crateLeft + 53 - font.getStringWidth(itemCount), crateTop + 107, fontColor); - - PLAYER_INVENTORY.draw(this, invLeft, invTop); - font.drawString("Inventory", invLeft + 7, invTop + 6, 0x666666); - - for (int slot = 0; slot < 16; slot++) { - if (allowedItems.getState() > slot * 64) - continue; - int x = crateLeft + 23 + (slot % 4) * 18; - int y = crateTop + 24 + (slot / 4) * 18; - ScreenResources.FLEXCRATE_LOCKED_SLOT.draw(this, x, y); - } - - ScreenElementRenderer.renderBlock(this::getRenderedBlock); - } - - @Override - public void tick() { - super.tick(); - if (lastModification >= 0) - lastModification++; - - if (lastModification >= 15) { - lastModification = -1; - - } - } - - public BlockState getRenderedBlock() { - GlStateManager.translated(guiLeft + FLEXCRATE.width + 145, guiTop + 115, 0); - GlStateManager.rotatef(50, -.5f, 1, -.2f); - return AllBlocks.FLEXCRATE.get().getDefaultState(); - } - -} diff --git a/src/main/java/com/simibubi/create/modules/logistics/FlexCrateTileEntity.java b/src/main/java/com/simibubi/create/modules/logistics/FlexCrateTileEntity.java deleted file mode 100644 index 3adf6f527..000000000 --- a/src/main/java/com/simibubi/create/modules/logistics/FlexCrateTileEntity.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.simibubi.create.modules.logistics; - -import com.simibubi.create.AllTileEntities; -import com.simibubi.create.foundation.block.SyncedTileEntity; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.INamedContainerProvider; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.Direction; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.CapabilityItemHandler; -import net.minecraftforge.items.ItemStackHandler; - -public class FlexcrateTileEntity extends SyncedTileEntity implements INamedContainerProvider { - - public class Inv extends ItemStackHandler { - public Inv() { - super(16); - } - - @Override - public int getSlotLimit(int slot) { - if (slot < allowedAmount / 64) - return super.getSlotLimit(slot); - else if (slot == allowedAmount / 64) - return allowedAmount % 64; - return 0; - } - - @Override - public boolean isItemValid(int slot, ItemStack stack) { - if (slot > allowedAmount / 64) - return false; - return super.isItemValid(slot, stack); - } - - @Override - protected void onContentsChanged(int slot) { - super.onContentsChanged(slot); - markDirty(); - } - } - - public Inv inventory; - public int allowedAmount; - public int itemCount; - - public FlexcrateTileEntity() { - this(AllTileEntities.FLEXCRATE.type); - } - - public FlexcrateTileEntity(TileEntityType type) { - super(type); - allowedAmount = 512; - itemCount = 10; - inventory = new Inv(); - } - - @Override - public Container createMenu(int id, PlayerInventory inventory, PlayerEntity player) { - return new FlexcrateContainer(id, inventory, this); - } - - @Override - public CompoundNBT write(CompoundNBT compound) { - compound.putInt("AllowedAmount", allowedAmount); - compound.put("Inventory", inventory.serializeNBT()); - return super.write(compound); - } - - @Override - public void read(CompoundNBT compound) { - allowedAmount = compound.getInt("AllowedAmount"); - inventory.deserializeNBT(compound.getCompound("Inventory")); - super.read(compound); - } - - @Override - public ITextComponent getDisplayName() { - return new StringTextComponent(getType().getRegistryName().toString()); - } - - public void sendToContainer(PacketBuffer buffer) { - buffer.writeBlockPos(getPos()); - buffer.writeCompoundTag(getUpdateTag()); - } - - @Override - public LazyOptional getCapability(Capability capability, Direction facing) { - if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { - return LazyOptional.of(() -> inventory).cast(); - } - return super.getCapability(capability, facing); - } - -} diff --git a/src/main/java/com/simibubi/create/modules/logistics/FrequencyHandler.java b/src/main/java/com/simibubi/create/modules/logistics/FrequencyHandler.java new file mode 100644 index 000000000..2b30552bc --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/logistics/FrequencyHandler.java @@ -0,0 +1,131 @@ +package com.simibubi.create.modules.logistics; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.Pair; + +import com.simibubi.create.Create; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.world.IWorld; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; + +@EventBusSubscriber +public class FrequencyHandler { + + public static final int RANGE = 128; + + static Map, List>> connections = new HashMap<>(); + + public static class Frequency { + private ItemStack stack; + private Item item; + private int color; + + public Frequency(ItemStack stack) { + this.stack = stack; + item = stack.getItem(); + CompoundNBT displayTag = stack.getChildTag("display"); + color = displayTag != null && displayTag.contains("color") ? displayTag.getInt("color") : -1; + } + + public ItemStack getStack() { + return stack; + } + + @Override + public int hashCode() { + return item.hashCode() ^ color; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof Frequency ? ((Frequency) obj).item == item && ((Frequency) obj).color == color + : false; + } + + } + + @SubscribeEvent + public static void onLoadWorld(WorldEvent.Load event) { + connections.put(event.getWorld(), new HashMap<>()); + Create.logger.info("Prepared network space for " + event.getWorld().getDimension().getType().getRegistryName()); + } + + @SubscribeEvent + public static void onUnloadWorld(WorldEvent.Unload event) { + connections.remove(event.getWorld()); + Create.logger.info("Removed network space for " + event.getWorld().getDimension().getType().getRegistryName()); + } + + private static Pair getNetworkKey(IHaveWireless actor) { + return Pair.of(actor.getFrequencyFirst(), actor.getFrequencyLast()); + } + + public static List getNetworkOf(IHaveWireless actor) { + Map, List> networksInWorld = networksIn(actor.getWorld()); + Pair key = getNetworkKey(actor); + if (!networksInWorld.containsKey(key)) + networksInWorld.put(key, new ArrayList<>()); + return networksInWorld.get(key); + } + + public static void addToNetwork(IHaveWireless actor) { + getNetworkOf(actor).add(actor); + updateNetworkOf(actor); + } + + public static void removeFromNetwork(IHaveWireless actor) { + List network = getNetworkOf(actor); + network.remove(actor); + if (network.isEmpty()) { + networksIn(actor.getWorld()).remove(getNetworkKey(actor)); + return; + } + updateNetworkOf(actor); + } + + public static void updateNetworkOf(IHaveWireless actor) { + List network = getNetworkOf(actor); + boolean powered = false; + + // Update from Transmitters + for (IHaveWireless other : network) { + if (!other.isLoaded() || !withinRange(actor, other)) + continue; + if (other instanceof ITransmitWireless && ((ITransmitWireless) other).getSignal()) { + powered = true; + break; + } + } + + // Update the Receivers + for (IHaveWireless other : network) { + if (!other.isLoaded() || !withinRange(actor, other)) + continue; + if (other instanceof IReceiveWireless) + ((IReceiveWireless) other).setSignal(powered); + } + } + + public static boolean withinRange(IHaveWireless from, IHaveWireless to) { + return from.getPos().withinDistance(to.getPos(), RANGE); + } + + public static Map, List> networksIn(IWorld world) { + if (!connections.containsKey(world)) { + Create.logger.warn( + "Tried to Access unprepared network space of " + world.getDimension().getType().getRegistryName()); + return new HashMap<>(); + } + return connections.get(world); + } + +} diff --git a/src/main/java/com/simibubi/create/modules/logistics/IHaveWireless.java b/src/main/java/com/simibubi/create/modules/logistics/IHaveWireless.java new file mode 100644 index 000000000..e4ea2c2c3 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/logistics/IHaveWireless.java @@ -0,0 +1,19 @@ +package com.simibubi.create.modules.logistics; + +import com.simibubi.create.modules.logistics.FrequencyHandler.Frequency; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public interface IHaveWireless { + + public Frequency getFrequencyFirst(); + public Frequency getFrequencyLast(); + public World getWorld(); + public BlockPos getPos(); + + public default boolean isLoaded() { + return getWorld().isBlockPresent(getPos()); + } + +} diff --git a/src/main/java/com/simibubi/create/modules/logistics/IReceiveWireless.java b/src/main/java/com/simibubi/create/modules/logistics/IReceiveWireless.java new file mode 100644 index 000000000..202b0fc58 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/logistics/IReceiveWireless.java @@ -0,0 +1,7 @@ +package com.simibubi.create.modules.logistics; + +public interface IReceiveWireless extends IHaveWireless { + + public void setSignal(boolean powered); + +} diff --git a/src/main/java/com/simibubi/create/modules/logistics/ITransmitWireless.java b/src/main/java/com/simibubi/create/modules/logistics/ITransmitWireless.java new file mode 100644 index 000000000..96a88b3c9 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/logistics/ITransmitWireless.java @@ -0,0 +1,10 @@ +package com.simibubi.create.modules.logistics; + +public interface ITransmitWireless extends IHaveWireless { + + public boolean getSignal(); + public default void notifySignalChange() { + FrequencyHandler.updateNetworkOf(this); + } + +} diff --git a/src/main/java/com/simibubi/create/modules/logistics/RedstoneBridgeTileEntity.java b/src/main/java/com/simibubi/create/modules/logistics/RedstoneBridgeTileEntity.java deleted file mode 100644 index c2c032799..000000000 --- a/src/main/java/com/simibubi/create/modules/logistics/RedstoneBridgeTileEntity.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.simibubi.create.modules.logistics; - -import static net.minecraft.state.properties.BlockStateProperties.POWERED; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.tuple.Pair; - -import com.simibubi.create.AllTileEntities; -import com.simibubi.create.foundation.block.SyncedTileEntity; - -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -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.math.BlockPos; - -public class RedstoneBridgeTileEntity extends SyncedTileEntity implements ITickableTileEntity { - - public static final int RANGE = 128; - - static Map, List> connections; - - public static class Frequency { - private ItemStack stack; - private Item item; - private int color; - - public Frequency(ItemStack stack) { - this.stack = stack; - item = stack.getItem(); - CompoundNBT displayTag = stack.getChildTag("display"); - color = displayTag != null && displayTag.contains("color") ? displayTag.getInt("color") : -1; - } - - public ItemStack getStack() { - return stack; - } - - @Override - public int hashCode() { - return item.hashCode() ^ color; - } - - @Override - public boolean equals(Object obj) { - return obj instanceof Frequency ? ((Frequency) obj).item == item && ((Frequency) obj).color == color - : false; - } - - } - - public Frequency frequencyFirst; - public Frequency frequencyLast; - public boolean networkChanged; - - public RedstoneBridgeTileEntity() { - super(AllTileEntities.REDSTONE_BRIDGE.type); - frequencyFirst = new Frequency(ItemStack.EMPTY); - frequencyLast = new Frequency(ItemStack.EMPTY); - - if (connections == null) - connections = new HashMap<>(); - } - - @Override - public void onLoad() { - super.onLoad(); - if (world.isRemote) - return; - - addToNetwork(); - } - - @Override - public void remove() { - super.remove(); - if (world.isRemote) - return; - - removeFromNetwork(); - } - - public void setFrequency(boolean first, ItemStack stack) { - stack = stack.copy(); - stack.setCount(1); - ItemStack toCompare = first ? frequencyFirst.stack : frequencyLast.stack; - boolean changed = !ItemStack.areItemsEqual(stack, toCompare) - || !ItemStack.areItemStackTagsEqual(stack, toCompare); - - if (changed) - removeFromNetwork(); - - if (first) - frequencyFirst = new Frequency(stack); - else - frequencyLast = new Frequency(stack); - - if (!changed) - return; - - world.notifyBlockUpdate(pos, getBlockState(), getBlockState(), 18); - addToNetwork(); - } - - protected Pair getNetworkKey() { - return Pair.of(frequencyFirst, frequencyLast); - } - - protected void addToNetwork() { - Pair networkKey = getNetworkKey(); - List TEs = connections.getOrDefault(networkKey, new ArrayList<>()); - TEs.add(this); - connections.put(networkKey, TEs); - notifyNetwork(); - } - - protected void removeFromNetwork() { - Pair networkKey = getNetworkKey(); - List TEs = connections.get(networkKey); - if (TEs != null) - TEs.remove(this); - if (TEs.isEmpty()) { - connections.remove(networkKey); - return; - } - notifyNetwork(); - } - - protected boolean isNetworkPowered() { - List TEs = connections.get(getNetworkKey()); - for (RedstoneBridgeTileEntity te : TEs) { - if (te == this) - continue; - if (te.canProvideNetworkPower()) - return true; - } - return false; - } - - protected void notifyNetwork() { - for (RedstoneBridgeTileEntity te : connections.get(getNetworkKey())) - te.networkChanged = true; - } - - public boolean canProvideNetworkPower() { - return isBlockPowered() && isTransmitter(); - } - - public boolean isTransmitter() { - return !getBlockState().get(RedstoneBridgeBlock.RECEIVER); - } - - public boolean isBlockPowered() { - return getBlockState().get(POWERED); - } - - public void blockChanged() { - notifyNetwork(); - networkChanged = true; - } - - @Override - public CompoundNBT write(CompoundNBT compound) { - compound.put("FrequencyFirst", frequencyFirst.getStack().write(new CompoundNBT())); - compound.put("FrequencyLast", frequencyLast.getStack().write(new CompoundNBT())); - return super.write(compound); - } - - @Override - public void read(CompoundNBT compound) { - frequencyFirst = new Frequency(ItemStack.read(compound.getCompound("FrequencyFirst"))); - frequencyLast = new Frequency(ItemStack.read(compound.getCompound("FrequencyLast"))); - super.read(compound); - } - - @Override - public void tick() { - if (!networkChanged) - return; - networkChanged = false; - - if (isTransmitter()) - return; - if (isNetworkPowered() != isBlockPowered()) { - world.setBlockState(pos, getBlockState().cycle(POWERED)); - Direction attachedFace = getBlockState().get(BlockStateProperties.FACING).getOpposite(); - BlockPos attachedPos = pos.offset(attachedFace); - world.notifyNeighbors(attachedPos, world.getBlockState(attachedPos).getBlock()); - return; - } - } - -} diff --git a/src/main/java/com/simibubi/create/modules/logistics/StockswitchTileEntity.java b/src/main/java/com/simibubi/create/modules/logistics/StockswitchTileEntity.java deleted file mode 100644 index da3bd7f31..000000000 --- a/src/main/java/com/simibubi/create/modules/logistics/StockswitchTileEntity.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.simibubi.create.modules.logistics; - -import com.simibubi.create.AllTileEntities; -import com.simibubi.create.foundation.block.SyncedTileEntity; - -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.tileentity.TileEntityType; - -public class StockswitchTileEntity extends SyncedTileEntity { - - float onWhenAbove; - float offWhenBelow; - float currentLevel; - - public StockswitchTileEntity() { - this(AllTileEntities.STOCKSWITCH.type); - } - - public StockswitchTileEntity(TileEntityType typeIn) { - super(typeIn); - onWhenAbove = .75f; - offWhenBelow = .25f; - } - - @Override - public void read(CompoundNBT compound) { - - onWhenAbove = compound.getFloat("OnAbove"); - offWhenBelow = compound.getFloat("OffBelow"); - updateCurrentLevel(); - - super.read(compound); - } - - @Override - public CompoundNBT write(CompoundNBT compound) { - - compound.putFloat("OnAbove", onWhenAbove); - compound.putFloat("OffBelow", offWhenBelow); - - return super.write(compound); - } - - private void updateCurrentLevel() { - - } - -} diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/ExtractorBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/ExtractorBlock.java new file mode 100644 index 000000000..3726453d4 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/logistics/block/ExtractorBlock.java @@ -0,0 +1,78 @@ +package com.simibubi.create.modules.logistics.block; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.HorizontalBlock; +import net.minecraft.item.BlockItemUseContext; +import net.minecraft.state.BooleanProperty; +import net.minecraft.state.StateContainer.Builder; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.util.math.shapes.VoxelShape; +import net.minecraft.util.math.shapes.VoxelShapes; +import net.minecraft.world.IBlockReader; +import net.minecraft.world.World; + +public class ExtractorBlock extends HorizontalBlock { + + public static BooleanProperty POWERED = BlockStateProperties.POWERED; + public static final VoxelShape SHAPE_NORTH = makeCuboidShape(4, 2, -1, 12, 10, 5), + SHAPE_SOUTH = makeCuboidShape(4, 2, 11, 12, 10, 17), SHAPE_WEST = makeCuboidShape(-1, 2, 4, 5, 10, 12), + SHAPE_EAST = makeCuboidShape(11, 2, 4, 17, 10, 12); + + public ExtractorBlock() { + super(Properties.from(Blocks.ANDESITE)); + setDefaultState(getDefaultState().with(POWERED, false)); + } + + @Override + protected void fillStateContainer(Builder builder) { + builder.add(HORIZONTAL_FACING, POWERED); + super.fillStateContainer(builder); + } + + @Override + public BlockState getStateForPlacement(BlockItemUseContext context) { + BlockState state = getDefaultState(); + + if (context.getFace().getAxis().isHorizontal()) { + state = state.with(HORIZONTAL_FACING, context.getFace().getOpposite()); + } else { + state = state.with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing()); + } + + return state.with(POWERED, Boolean.valueOf(context.getWorld().isBlockPowered(context.getPos()))); + } + + @Override + public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, + boolean isMoving) { + if (worldIn.isRemote) + return; + + boolean previouslyPowered = state.get(POWERED); + if (previouslyPowered != worldIn.isBlockPowered(pos)) { + worldIn.setBlockState(pos, state.cycle(POWERED), 2); + } + } + + @Override + public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + Direction facing = state.get(HORIZONTAL_FACING); + + if (facing == Direction.EAST) + return SHAPE_EAST; + if (facing == Direction.WEST) + return SHAPE_WEST; + if (facing == Direction.SOUTH) + return SHAPE_SOUTH; + if (facing == Direction.NORTH) + return SHAPE_NORTH; + + return VoxelShapes.empty(); + } + +} diff --git a/src/main/java/com/simibubi/create/modules/logistics/FlexcrateBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateBlock.java similarity index 98% rename from src/main/java/com/simibubi/create/modules/logistics/FlexcrateBlock.java rename to src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateBlock.java index fba8e41a2..09922e817 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/FlexcrateBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateBlock.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.logistics; +package com.simibubi.create.modules.logistics.block; import com.simibubi.create.foundation.block.InfoBlock; import com.simibubi.create.foundation.utility.ItemDescription; diff --git a/src/main/java/com/simibubi/create/modules/logistics/FlexcrateContainer.java b/src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateContainer.java similarity index 94% rename from src/main/java/com/simibubi/create/modules/logistics/FlexcrateContainer.java rename to src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateContainer.java index 82c1ec111..0755458ee 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/FlexcrateContainer.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateContainer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.logistics; +package com.simibubi.create.modules.logistics.block; import com.simibubi.create.AllContainers; @@ -63,8 +63,10 @@ public class FlexcrateContainer extends Container { return ItemStack.EMPTY; ItemStack stack = clickedSlot.getStack(); - if (index < 16) + if (index < 16) { mergeItemStack(stack, 16, inventorySlots.size(), false); + te.inventory.onContentsChanged(index); + } else mergeItemStack(stack, 0, 15, false); diff --git a/src/main/java/com/simibubi/create/modules/logistics/FlexcrateScreen.java b/src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateScreen.java similarity index 88% rename from src/main/java/com/simibubi/create/modules/logistics/FlexcrateScreen.java rename to src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateScreen.java index cf2fb3ace..2bb0a4feb 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/FlexcrateScreen.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateScreen.java @@ -1,15 +1,17 @@ -package com.simibubi.create.modules.logistics; +package com.simibubi.create.modules.logistics.block; import static com.simibubi.create.foundation.gui.ScreenResources.FLEXCRATE; import static com.simibubi.create.foundation.gui.ScreenResources.PLAYER_INVENTORY; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.AllBlocks; +import com.simibubi.create.AllPackets; import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.foundation.gui.ScreenResources; import com.simibubi.create.foundation.gui.widgets.Label; import com.simibubi.create.foundation.gui.widgets.ScrollInput; +import com.simibubi.create.modules.logistics.packet.ConfigureFlexcratePacket; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerInventory; @@ -71,16 +73,21 @@ public class FlexcrateScreen extends AbstractSimiContainerScreen= 0) lastModification++; - + if (lastModification >= 15) { lastModification = -1; - + AllPackets.channel.sendToServer(new ConfigureFlexcratePacket(te.getPos(), allowedItems.getState())); } } diff --git a/src/main/java/com/simibubi/create/modules/logistics/FlexcrateTileEntity.java b/src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateTileEntity.java similarity index 86% rename from src/main/java/com/simibubi/create/modules/logistics/FlexcrateTileEntity.java rename to src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateTileEntity.java index 3adf6f527..320223d0c 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/FlexcrateTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateTileEntity.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.logistics; +package com.simibubi.create.modules.logistics.block; import com.simibubi.create.AllTileEntities; import com.simibubi.create.foundation.block.SyncedTileEntity; @@ -17,6 +17,7 @@ import net.minecraft.util.text.StringTextComponent; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemStackHandler; public class FlexcrateTileEntity extends SyncedTileEntity implements INamedContainerProvider { @@ -46,12 +47,18 @@ public class FlexcrateTileEntity extends SyncedTileEntity implements INamedConta protected void onContentsChanged(int slot) { super.onContentsChanged(slot); markDirty(); + + itemCount = 0; + for (int i = 0; i < getSlots(); i++) { + itemCount += getStackInSlot(i).getCount(); + } } } public Inv inventory; public int allowedAmount; public int itemCount; + protected LazyOptional invHandler; public FlexcrateTileEntity() { this(AllTileEntities.FLEXCRATE.type); @@ -62,6 +69,7 @@ public class FlexcrateTileEntity extends SyncedTileEntity implements INamedConta allowedAmount = 512; itemCount = 10; inventory = new Inv(); + invHandler = LazyOptional.of(() -> inventory); } @Override @@ -93,11 +101,16 @@ public class FlexcrateTileEntity extends SyncedTileEntity implements INamedConta buffer.writeCompoundTag(getUpdateTag()); } + @Override + public void remove() { + super.remove(); + invHandler.invalidate(); + } + @Override public LazyOptional getCapability(Capability capability, Direction facing) { - if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { - return LazyOptional.of(() -> inventory).cast(); - } + if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) + return invHandler.cast(); return super.getCapability(capability, facing); } diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/LinkedExtractorBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/LinkedExtractorBlock.java new file mode 100644 index 000000000..e77788e9b --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/logistics/block/LinkedExtractorBlock.java @@ -0,0 +1,31 @@ +package com.simibubi.create.modules.logistics.block; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.item.BlockItemUseContext; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class LinkedExtractorBlock extends ExtractorBlock { + + public LinkedExtractorBlock() { + super(); + } + + @Override + public BlockRenderLayer getRenderLayer() { + return BlockRenderLayer.CUTOUT; + } + + @Override + public BlockState getStateForPlacement(BlockItemUseContext context) { + return super.getStateForPlacement(context).with(POWERED, false); + } + + @Override + public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, + boolean isMoving) { + } + +} diff --git a/src/main/java/com/simibubi/create/modules/logistics/RedstoneBridgeBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneBridgeBlock.java similarity index 90% rename from src/main/java/com/simibubi/create/modules/logistics/RedstoneBridgeBlock.java rename to src/main/java/com/simibubi/create/modules/logistics/block/RedstoneBridgeBlock.java index 801e27483..c7443451f 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/RedstoneBridgeBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneBridgeBlock.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.logistics; +package com.simibubi.create.modules.logistics.block; import java.util.ArrayList; import java.util.List; @@ -42,7 +42,6 @@ import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; import net.minecraft.util.text.ITextComponent; import net.minecraft.world.IBlockReader; -import net.minecraft.world.IWorld; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; @@ -61,10 +60,8 @@ public class RedstoneBridgeBlock extends ProperDirectionalBlock implements ITool public static final VoxelShape UP_SHAPE = makeCuboidShape(2, 0, 2, 14, 3, 14), DOWN_SHAPE = makeCuboidShape(2, 13, 2, 14, 16, 14); - public static final VoxelShape - SOUTH_SHAPE = makeCuboidShape(3, 1, -1, 13, 15, 3), - NORTH_SHAPE = makeCuboidShape(3, 1, 13, 13, 15, 17), - EAST_SHAPE = makeCuboidShape(-1, 1, 3, 3, 15, 13), + public static final VoxelShape SOUTH_SHAPE = makeCuboidShape(3, 1, -1, 13, 15, 3), + NORTH_SHAPE = makeCuboidShape(3, 1, 13, 13, 15, 17), EAST_SHAPE = makeCuboidShape(-1, 1, 3, 3, 15, 13), WEST_SHAPE = makeCuboidShape(13, 1, 3, 17, 15, 13); private TooltipHolder info; @@ -88,47 +85,34 @@ public class RedstoneBridgeBlock extends ProperDirectionalBlock implements ITool } } + updateTransmittedSignal(state, worldIn, pos, blockFacing); + } + + @Override + public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) { + updateTransmittedSignal(state, worldIn, pos, state.get(FACING)); + } + + private void updateTransmittedSignal(BlockState state, World worldIn, BlockPos pos, Direction blockFacing) { if (worldIn.isRemote) return; if (state.get(RECEIVER)) return; - + + boolean shouldPower = worldIn.getWorld().isBlockPowered(pos.offset(blockFacing.getOpposite())) + || worldIn.getWorld().isBlockPowered(pos); boolean previouslyPowered = state.get(POWERED); - if (previouslyPowered != worldIn.isBlockPowered(pos.offset(blockFacing.getOpposite()))) { + + if (previouslyPowered != shouldPower) { worldIn.setBlockState(pos, state.cycle(POWERED), 2); - + RedstoneBridgeTileEntity te = (RedstoneBridgeTileEntity) worldIn.getTileEntity(pos); if (te == null) return; - te.blockChanged(); + te.transmit(!previouslyPowered); } } - @Override - public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, - BlockPos currentPos, BlockPos facingPos) { - boolean shouldPower = false; - Direction blockFacing = stateIn.get(FACING); - - if (worldIn.getWorld().isRemote) - return stateIn; - if (stateIn.get(RECEIVER)) - return stateIn; - - shouldPower = worldIn.getWorld().isBlockPowered(currentPos.offset(blockFacing.getOpposite())) - || worldIn.getWorld().isBlockPowered(currentPos); - if (stateIn.get(POWERED) != shouldPower) { - - RedstoneBridgeTileEntity te = (RedstoneBridgeTileEntity) worldIn.getTileEntity(currentPos); - if (te == null) - return stateIn; - te.blockChanged(); - - return stateIn.with(POWERED, shouldPower); - } - return stateIn; - } - @Override public boolean canProvidePower(BlockState state) { return state.get(POWERED) && state.get(RECEIVER); @@ -177,8 +161,13 @@ public class RedstoneBridgeBlock extends ProperDirectionalBlock implements ITool if (player.isSneaking()) { if (!worldIn.isRemote) { - worldIn.setBlockState(pos, state.cycle(RECEIVER)); - te.blockChanged(); + Boolean wasReceiver = state.get(RECEIVER); + boolean blockPowered = worldIn.isBlockPowered(pos); + worldIn.setBlockState(pos, state.cycle(RECEIVER).with(POWERED, blockPowered), 3); + if (wasReceiver) { + te.transmit(worldIn.isBlockPowered(pos)); + } else + te.transmit(false); } return true; } diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneBridgeTileEntity.java b/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneBridgeTileEntity.java new file mode 100644 index 000000000..993ef9408 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneBridgeTileEntity.java @@ -0,0 +1,135 @@ +package com.simibubi.create.modules.logistics.block; + +import static net.minecraft.state.properties.BlockStateProperties.POWERED; + +import com.simibubi.create.AllTileEntities; +import com.simibubi.create.foundation.block.SyncedTileEntity; +import com.simibubi.create.modules.logistics.FrequencyHandler; +import com.simibubi.create.modules.logistics.FrequencyHandler.Frequency; +import com.simibubi.create.modules.logistics.IReceiveWireless; +import com.simibubi.create.modules.logistics.ITransmitWireless; + +import net.minecraft.item.ItemStack; +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.math.BlockPos; + +public class RedstoneBridgeTileEntity extends SyncedTileEntity + implements ITickableTileEntity, IReceiveWireless, ITransmitWireless { + + public Frequency frequencyFirst; + public Frequency frequencyLast; + public boolean receivedSignal; + public boolean transmittedSignal; + + public RedstoneBridgeTileEntity() { + super(AllTileEntities.REDSTONE_BRIDGE.type); + frequencyFirst = new Frequency(ItemStack.EMPTY); + frequencyLast = new Frequency(ItemStack.EMPTY); + } + + @Override + public void onLoad() { + super.onLoad(); + if (world.isRemote) + return; + FrequencyHandler.addToNetwork(this); + } + + @Override + public void remove() { + super.remove(); + if (world.isRemote) + return; + FrequencyHandler.removeFromNetwork(this); + } + + public void setFrequency(boolean first, ItemStack stack) { + stack = stack.copy(); + stack.setCount(1); + ItemStack toCompare = first ? frequencyFirst.getStack() : frequencyLast.getStack(); + boolean changed = !ItemStack.areItemsEqual(stack, toCompare) + || !ItemStack.areItemStackTagsEqual(stack, toCompare); + + if (changed) + FrequencyHandler.removeFromNetwork(this); + + if (first) + frequencyFirst = new Frequency(stack); + else + frequencyLast = new Frequency(stack); + + if (!changed) + return; + + sendData(); + FrequencyHandler.addToNetwork(this); + } + + @Override + public Frequency getFrequencyFirst() { + return frequencyFirst; + } + + @Override + public Frequency getFrequencyLast() { + return frequencyLast; + } + + @Override + public boolean getSignal() { + return transmittedSignal; + } + + public void transmit(boolean signal) { + transmittedSignal = signal; + notifySignalChange(); + } + + @Override + public void setSignal(boolean powered) { + receivedSignal = powered; + } + + protected boolean isTransmitter() { + return !getBlockState().get(RedstoneBridgeBlock.RECEIVER); + } + + protected boolean isBlockPowered() { + return getBlockState().get(POWERED); + } + + @Override + public CompoundNBT write(CompoundNBT compound) { + compound.put("FrequencyFirst", frequencyFirst.getStack().write(new CompoundNBT())); + compound.put("FrequencyLast", frequencyLast.getStack().write(new CompoundNBT())); + compound.putBoolean("Transmit", transmittedSignal); + return super.write(compound); + } + + @Override + public void read(CompoundNBT compound) { + frequencyFirst = new Frequency(ItemStack.read(compound.getCompound("FrequencyFirst"))); + frequencyLast = new Frequency(ItemStack.read(compound.getCompound("FrequencyLast"))); + transmittedSignal = compound.getBoolean("Transmit"); + super.read(compound); + } + + @Override + public void tick() { + if (isTransmitter()) + return; + if (world.isRemote) + return; + if (receivedSignal != isBlockPowered()) { + world.setBlockState(pos, getBlockState().cycle(POWERED)); + Direction attachedFace = getBlockState().get(BlockStateProperties.FACING).getOpposite(); + BlockPos attachedPos = pos.offset(attachedFace); + world.notifyNeighbors(attachedPos, world.getBlockState(attachedPos).getBlock()); + return; + } + } + +} diff --git a/src/main/java/com/simibubi/create/modules/logistics/RedstoneBridgeTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneBridgeTileEntityRenderer.java similarity index 98% rename from src/main/java/com/simibubi/create/modules/logistics/RedstoneBridgeTileEntityRenderer.java rename to src/main/java/com/simibubi/create/modules/logistics/block/RedstoneBridgeTileEntityRenderer.java index 91fb3ac7d..c8d47e9d8 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/RedstoneBridgeTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneBridgeTileEntityRenderer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.logistics; +package com.simibubi.create.modules.logistics.block; import org.apache.commons.lang3.tuple.Pair; diff --git a/src/main/java/com/simibubi/create/modules/logistics/StockswitchBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchBlock.java similarity index 70% rename from src/main/java/com/simibubi/create/modules/logistics/StockswitchBlock.java rename to src/main/java/com/simibubi/create/modules/logistics/block/StockswitchBlock.java index 3acabde18..fd425fe38 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/StockswitchBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchBlock.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.logistics; +package com.simibubi.create.modules.logistics.block; import java.util.List; @@ -19,11 +19,13 @@ import net.minecraft.item.ItemStack; import net.minecraft.state.IntegerProperty; import net.minecraft.state.StateContainer.Builder; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Direction; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.text.ITextComponent; import net.minecraft.world.IBlockReader; +import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -43,6 +45,47 @@ public class StockswitchBlock extends HorizontalBlock implements ITooltip { public boolean isSolid(BlockState state) { return false; } + + @Override + public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) { + updateObservedInventory(state, worldIn, pos); + } + + @Override + public void onNeighborChange(BlockState state, IWorldReader world, BlockPos pos, BlockPos neighbor) { + if (world.isRemote()) + return; + if (!isObserving(state, pos, neighbor)) + return; + updateObservedInventory(state, world, pos); + } + + private void updateObservedInventory(BlockState state, IWorldReader world, BlockPos pos) { + StockswitchTileEntity te = (StockswitchTileEntity) world.getTileEntity(pos); + if (te == null) + return; + te.updateCurrentLevel(); + } + + private boolean isObserving(BlockState state, BlockPos pos, BlockPos observing) { + return observing.equals(pos.offset(state.get(HORIZONTAL_FACING))); + } + + @Override + public boolean canConnectRedstone(BlockState state, IBlockReader world, BlockPos pos, Direction side) { + return side != null && side.getOpposite() != state.get(HORIZONTAL_FACING); + } + + @Override + public boolean canProvidePower(BlockState state) { + return true; + } + + @Override + public int getWeakPower(BlockState blockState, IBlockReader blockAccess, BlockPos pos, Direction side) { + StockswitchTileEntity te = (StockswitchTileEntity) blockAccess.getTileEntity(pos); + return te == null || !te.powered ? 0 : 15 ; + } @Override public void addInformation(ItemStack stack, IBlockReader worldIn, List tooltip, diff --git a/src/main/java/com/simibubi/create/modules/logistics/StockswitchScreen.java b/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchScreen.java similarity index 75% rename from src/main/java/com/simibubi/create/modules/logistics/StockswitchScreen.java rename to src/main/java/com/simibubi/create/modules/logistics/block/StockswitchScreen.java index 9df29f301..52d8c8746 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/StockswitchScreen.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchScreen.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.logistics; +package com.simibubi.create.modules.logistics.block; import static com.simibubi.create.foundation.gui.ScreenResources.STOCKSWITCH; @@ -6,11 +6,13 @@ import java.util.Arrays; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.AllBlocks; +import com.simibubi.create.AllPackets; import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.foundation.gui.ScreenResources; import com.simibubi.create.foundation.gui.widgets.Label; import com.simibubi.create.foundation.gui.widgets.ScrollInput; +import com.simibubi.create.modules.logistics.packet.ConfigureStockswitchPacket; import net.minecraft.block.BlockState; @@ -21,10 +23,13 @@ public class StockswitchScreen extends AbstractSimiScreen { private ScrollInput onAbove; private Label onAboveLabel; + private int lastModification; private StockswitchTileEntity te; + private float cursorPos; public StockswitchScreen(StockswitchTileEntity te) { this.te = te; + lastModification = -1; } @Override @@ -32,11 +37,13 @@ public class StockswitchScreen extends AbstractSimiScreen { setWindowSize(STOCKSWITCH.width + 50, STOCKSWITCH.height); super.init(); widgets.clear(); + cursorPos = te.currentLevel == -1 ? 0 : te.currentLevel; offBelowLabel = new Label(guiLeft + 116, guiTop + 72, "").colored(0xD3CBBE).withShadow(); offBelow = new ScrollInput(guiLeft + 113, guiTop + 69, 33, 14).withRange(0, 96).titled("Lower Threshold") .calling(state -> { offBelowLabel.text = state + "%"; + lastModification = 0; if (onAbove.getState() - 4 <= state) { onAbove.setState(state + 5); onAbove.onChanged(); @@ -47,6 +54,7 @@ public class StockswitchScreen extends AbstractSimiScreen { onAbove = new ScrollInput(guiLeft + 113, guiTop + 52, 33, 14).withRange(5, 101).titled("Upper Threshold") .calling(state -> { onAboveLabel.text = state + "%"; + lastModification = 0; if (offBelow.getState() + 4 >= state) { offBelow.setState(state - 5); offBelow.onChanged(); @@ -74,7 +82,6 @@ public class StockswitchScreen extends AbstractSimiScreen { ScreenResources sprite = ScreenResources.STOCKSWITCH_INTERVAL; float lowerBound = offBelow.getState() / 100f * (sprite.width - 20) + 10; float upperBound = onAbove.getState() / 100f * (sprite.width - 20) + 10; - float cursorPos = te.currentLevel * (sprite.width - 20) + 10; sprite.bind(); blit((int) (guiLeft + lowerBound), guiTop + 26, (int) (sprite.startX + lowerBound), sprite.startY, @@ -88,13 +95,41 @@ public class StockswitchScreen extends AbstractSimiScreen { ScreenResources.STOCKSWITCH_BOUND_LEFT.draw(this, (int) (guiLeft + lowerBound) - 1, guiTop + 24); ScreenResources.STOCKSWITCH_BOUND_RIGHT.draw(this, (int) (guiLeft + upperBound) - 5, guiTop + 24); - ScreenResources cursor = te.getWorld().isBlockPowered(te.getPos()) ? ScreenResources.STOCKSWITCH_CURSOR_ON + ScreenResources cursor = te.powered ? ScreenResources.STOCKSWITCH_CURSOR_ON : ScreenResources.STOCKSWITCH_CURSOR_OFF; - cursor.draw(this, (int) (guiLeft + cursorPos), guiTop + 24); + GlStateManager.pushMatrix(); + GlStateManager.translatef((cursorPos * (sprite.width - 20) + 10), 0, 0); + cursor.draw(this, guiLeft - 4, guiTop + 24); + GlStateManager.popMatrix(); ScreenElementRenderer.renderBlock(this::getRenderedBlock); } + @Override + public void tick() { + super.tick(); + + if (te.currentLevel == -1) + cursorPos = 0; + else + cursorPos += (te.currentLevel - cursorPos) / 4; + + if (lastModification >= 0) + lastModification++; + + if (lastModification >= 20) { + lastModification = -1; + AllPackets.channel.sendToServer( + new ConfigureStockswitchPacket(te.getPos(), offBelow.getState() / 100f, onAbove.getState() / 100f)); + } + } + + @Override + public void removed() { + AllPackets.channel.sendToServer( + new ConfigureStockswitchPacket(te.getPos(), offBelow.getState() / 100f, onAbove.getState() / 100f)); + } + public BlockState getRenderedBlock() { GlStateManager.translated(guiLeft + STOCKSWITCH.width + 50, guiTop + 100, 0); GlStateManager.rotatef(50, -.5f, 1, -.2f); diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchTileEntity.java b/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchTileEntity.java new file mode 100644 index 000000000..3922b79c1 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchTileEntity.java @@ -0,0 +1,130 @@ +package com.simibubi.create.modules.logistics.block; + +import com.simibubi.create.AllTileEntities; +import com.simibubi.create.foundation.block.SyncedTileEntity; + +import net.minecraft.block.BlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; + +public class StockswitchTileEntity extends SyncedTileEntity { + + public float onWhenAbove; + public float offWhenBelow; + public float currentLevel; + public boolean powered; + private LazyOptional observedInventory; + + public StockswitchTileEntity() { + this(AllTileEntities.STOCKSWITCH.type); + } + + public StockswitchTileEntity(TileEntityType typeIn) { + super(typeIn); + onWhenAbove = .75f; + offWhenBelow = .25f; + currentLevel = -1; + powered = false; + observedInventory = LazyOptional.empty(); + } + + @Override + public void read(CompoundNBT compound) { + + onWhenAbove = compound.getFloat("OnAbove"); + offWhenBelow = compound.getFloat("OffBelow"); + currentLevel = compound.getFloat("Current"); + powered = compound.getBoolean("Powered"); + + super.read(compound); + } + + @Override + public CompoundNBT write(CompoundNBT compound) { + + compound.putFloat("OnAbove", onWhenAbove); + compound.putFloat("OffBelow", offWhenBelow); + compound.putFloat("Current", currentLevel); + compound.putBoolean("Powered", powered); + + return super.write(compound); + } + + public float getLevel() { + return currentLevel; + } + + public void updateCurrentLevel() { + if (!observedInventory.isPresent()) { + if (!findNewInventory() && currentLevel != -1) { + world.setBlockState(pos, getBlockState().with(StockswitchBlock.INDICATOR, 0), 3); + currentLevel = -1; + powered = false; + world.notifyNeighbors(pos, getBlockState().getBlock()); + } + return; + } + + float occupied = 0; + float totalSpace = 0; + IItemHandler inv = observedInventory.orElse(null); + + for (int slot = 0; slot < inv.getSlots(); slot++) { + ItemStack stackInSlot = inv.getStackInSlot(slot); + int space = Math.min(stackInSlot.getMaxStackSize(), inv.getSlotLimit(slot)); + int count = stackInSlot.getCount(); + + if (space == 0) + continue; + + totalSpace += 1; + occupied += count * (1f / space); + } + + currentLevel = (float) occupied / totalSpace; + currentLevel = MathHelper.clamp(currentLevel, 0, 1); + + boolean previouslyPowered = powered; + if (powered && currentLevel <= offWhenBelow) + powered = false; + else if (!powered && currentLevel >= onWhenAbove) + powered = true; + boolean update = previouslyPowered != powered; + + int displayLevel = 0; + if (currentLevel > 0) + displayLevel = (int) (currentLevel * 6); + world.setBlockState(pos, getBlockState().with(StockswitchBlock.INDICATOR, displayLevel), update ? 3 : 2); + if (update) + world.notifyNeighbors(pos, getBlockState().getBlock()); + } + + private boolean findNewInventory() { + BlockPos invPos = getPos().offset(getBlockState().get(BlockStateProperties.HORIZONTAL_FACING)); + + if (!world.isBlockPresent(invPos)) + return false; + BlockState invState = world.getBlockState(invPos); + + if (!invState.hasTileEntity()) + return false; + TileEntity invTE = world.getTileEntity(invPos); + + observedInventory = invTE.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY); + if (observedInventory.isPresent()) { + updateCurrentLevel(); + return true; + } + + return false; + } + +} diff --git a/src/main/java/com/simibubi/create/modules/logistics/item/FilterItem.java b/src/main/java/com/simibubi/create/modules/logistics/item/FilterItem.java new file mode 100644 index 000000000..5b165b090 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/logistics/item/FilterItem.java @@ -0,0 +1,38 @@ +package com.simibubi.create.modules.logistics.item; + +import com.simibubi.create.foundation.item.InfoItem; +import com.simibubi.create.foundation.utility.ItemDescription; +import com.simibubi.create.foundation.utility.ItemDescription.Palette; + +import net.minecraft.client.renderer.color.IItemColor; +import net.minecraft.item.ItemStack; + +public class FilterItem extends InfoItem { + + public static class Color implements IItemColor { + @Override + public int getColor(ItemStack stack, int layer) { + if (layer == 0) + return 0xFFFFFF; + if (layer == 1) + return 0x6677AA; + if (layer == 2) + return 0x334477; + return 0; + } + } + + public FilterItem(Properties properties) { + super(properties); + } + + @Override + public ItemDescription getDescription() { + Palette color = Palette.Yellow; + return new ItemDescription(color) + .withSummary("Holds information for controlling input, output and detection of objects.") + .withControl("R-Click while Sneaking", "Opens the " + h("Configuration Screen", color)) + .withControl("When Entity punched", "Creates a filter with the target set to the Entity.").createTabs(); + } + +} diff --git a/src/main/java/com/simibubi/create/modules/logistics/packet/ConfigureFlexcratePacket.java b/src/main/java/com/simibubi/create/modules/logistics/packet/ConfigureFlexcratePacket.java new file mode 100644 index 000000000..a865a46b8 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/logistics/packet/ConfigureFlexcratePacket.java @@ -0,0 +1,37 @@ +package com.simibubi.create.modules.logistics.packet; + +import com.simibubi.create.foundation.packet.TileEntityConfigurationPacket; +import com.simibubi.create.modules.logistics.block.FlexcrateTileEntity; + +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.math.BlockPos; + +public class ConfigureFlexcratePacket extends TileEntityConfigurationPacket { + + private int maxItems; + + public ConfigureFlexcratePacket(PacketBuffer buffer) { + super(buffer); + } + + public ConfigureFlexcratePacket(BlockPos pos, int newMaxItems) { + super(pos); + this.maxItems = newMaxItems; + } + + @Override + protected void writeSettings(PacketBuffer buffer) { + buffer.writeInt(maxItems); + } + + @Override + protected void readSettings(PacketBuffer buffer) { + maxItems = buffer.readInt(); + } + + @Override + protected void applySettings(FlexcrateTileEntity te) { + te.allowedAmount = maxItems; + } + +} diff --git a/src/main/java/com/simibubi/create/modules/logistics/packet/ConfigureStockswitchPacket.java b/src/main/java/com/simibubi/create/modules/logistics/packet/ConfigureStockswitchPacket.java new file mode 100644 index 000000000..f548aae91 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/logistics/packet/ConfigureStockswitchPacket.java @@ -0,0 +1,42 @@ +package com.simibubi.create.modules.logistics.packet; + +import com.simibubi.create.foundation.packet.TileEntityConfigurationPacket; +import com.simibubi.create.modules.logistics.block.StockswitchTileEntity; + +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.math.BlockPos; + +public class ConfigureStockswitchPacket extends TileEntityConfigurationPacket { + + private float offBelow; + private float onAbove; + + public ConfigureStockswitchPacket(BlockPos pos, float offBelow, float onAbove) { + super(pos); + this.offBelow = offBelow; + this.onAbove = onAbove; + } + + public ConfigureStockswitchPacket(PacketBuffer buffer) { + super(buffer); + } + + @Override + protected void readSettings(PacketBuffer buffer) { + offBelow = buffer.readFloat(); + onAbove = buffer.readFloat(); + } + + @Override + protected void writeSettings(PacketBuffer buffer) { + buffer.writeFloat(offBelow); + buffer.writeFloat(onAbove); + } + + @Override + protected void applySettings(StockswitchTileEntity te) { + te.offWhenBelow = offBelow; + te.onWhenAbove = onAbove; + } + +} diff --git a/src/main/resources/assets/create/blockstates/extractor.json b/src/main/resources/assets/create/blockstates/extractor.json new file mode 100644 index 000000000..eb1574f3d --- /dev/null +++ b/src/main/resources/assets/create/blockstates/extractor.json @@ -0,0 +1,18 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "create:block/extractor" + }, + "variants": { + "powered": { + "true": { "model": "create:block/extractor_powered" }, + "false": { "model": "create:block/extractor" } + }, + "facing": { + "south": { "y": 180 }, + "east": { "y": 90 }, + "north": { "y": 0 }, + "west": { "y": 270 } + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/create/blockstates/linked_extractor.json b/src/main/resources/assets/create/blockstates/linked_extractor.json new file mode 100644 index 000000000..c526fed81 --- /dev/null +++ b/src/main/resources/assets/create/blockstates/linked_extractor.json @@ -0,0 +1,18 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "create:block/extractor_wireless" + }, + "variants": { + "powered": { + "true": { "model": "create:block/extractor_wireless_powered" }, + "false": { "model": "create:block/extractor_wireless" } + }, + "facing": { + "south": { "y": 180 }, + "east": { "y": 90 }, + "north": { "y": 0 }, + "west": { "y": 270 } + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/create/lang/en_us.json b/src/main/resources/assets/create/lang/en_us.json index 2cd532125..5ef5546e7 100644 --- a/src/main/resources/assets/create/lang/en_us.json +++ b/src/main/resources/assets/create/lang/en_us.json @@ -9,6 +9,7 @@ "item.create.blueprint_and_quill": "Schematic and Quill", "item.create.blueprint": "Schematic", "item.create.belt_connector": "Mechanical Belt", + "item.create.filter": "Filter", "block.create.gear": "Cogwheel", "block.create.large_gear": "Large Cogwheel", @@ -37,6 +38,8 @@ "block.create.redstone_bridge": "Redstone Bridge", "block.create.stockswitch": "Stockpile Switch", "block.create.flexcrate": "FlexCrate", + "block.create.extractor": "Extractor", + "block.create.linked_extractor": "Linked Extractor", "block.create.andesite_bricks": "Andesite Bricks", "block.create.diorite_bricks": "Diorite Bricks", diff --git a/src/main/resources/assets/create/models/block/extractor.json b/src/main/resources/assets/create/models/block/extractor.json new file mode 100644 index 000000000..bf006e499 --- /dev/null +++ b/src/main/resources/assets/create/models/block/extractor.json @@ -0,0 +1,75 @@ +{ + "__comment": "Model generated using MrCrayfish's Model Creator (https://mrcrayfish.com/tools?id=mc)", + "parent": "block/block", + "textures": { + "extractor": "create:block/extractor", + "particle": "create:block/extractor" + }, + "elements": [ + { + "name": "Bottom", + "from": [ 4, 2, -1 ], + "to": [ 12, 3, 5 ], + "faces": { + "east": { "texture": "#extractor", "uv": [ 0, 0, 6, 1 ], "rotation": 180 }, + "south": { "texture": "#extractor", "uv": [ 6, 7, 14, 8 ] }, + "west": { "texture": "#extractor", "uv": [ 0, 0, 6, 1 ] }, + "up": { "texture": "#extractor", "uv": [ 9, 0, 15, 8 ], "rotation": 90 }, + "down": { "texture": "#extractor", "uv": [ 0, 0, 6, 8 ], "rotation": 270 } + } + }, + { + "name": "Top", + "from": [ 4, 9, -1 ], + "to": [ 12, 10, 5 ], + "faces": { + "east": { "texture": "#extractor", "uv": [ 0, 0, 6, 1 ], "rotation": 180 }, + "south": { "texture": "#extractor", "uv": [ 6, 0, 14, 1 ] }, + "west": { "texture": "#extractor", "uv": [ 0, 0, 6, 1 ] }, + "up": { "texture": "#extractor", "uv": [ 0, 0, 6, 8 ], "rotation": 90 }, + "down": { "texture": "#extractor", "uv": [ 9, 0, 15, 8 ], "rotation": 270 } + } + }, + { + "name": "Side", + "from": [ 4, 3, -1 ], + "to": [ 5, 9, 5 ], + "faces": { + "east": { "texture": "#extractor", "uv": [ 9, 1, 15, 7 ], "rotation": 180 }, + "south": { "texture": "#extractor", "uv": [ 6, 1, 7, 7 ] }, + "west": { "texture": "#extractor", "uv": [ 0, 1, 6, 7 ] } + } + }, + { + "name": "Side", + "from": [ 11, 3, -1 ], + "to": [ 12, 9, 5 ], + "faces": { + "east": { "texture": "#extractor", "uv": [ 0, 1, 6, 7 ], "rotation": 180 }, + "south": { "texture": "#extractor", "uv": [ 13, 1, 14, 7 ] }, + "west": { "texture": "#extractor", "uv": [ 9, 1, 15, 7 ] } + } + }, + { + "name": "Center", + "from": [ 5, 3, 3 ], + "to": [ 11, 9, 4 ], + "faces": { + "south": { "texture": "#extractor", "uv": [ 7, 1, 13, 7 ] } + } + }, + { + "name": "FilterSpot", + "from": [ 5, 10, -0.6 ], + "to": [ 11, 12, 4 ], + "rotation": { "origin": [ 8, 11, -1 ], "axis": "x", "angle": 22.5 }, + "faces": { + "north": { "texture": "#extractor", "uv": [ 13, 1, 15, 7 ], "rotation": 90 }, + "east": { "texture": "#extractor", "uv": [ 0.1, 0, 4.7, 2 ], "rotation": 180 }, + "south": { "texture": "#extractor", "uv": [ 4, 1, 5, 7 ], "rotation": 270 }, + "west": { "texture": "#extractor", "uv": [ 0.1, 0, 4.7, 2 ] }, + "up": { "texture": "#extractor", "uv": [ 0, 9, 5, 15 ], "rotation": 90 } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/create/models/block/extractor_powered.json b/src/main/resources/assets/create/models/block/extractor_powered.json new file mode 100644 index 000000000..9e43e6d02 --- /dev/null +++ b/src/main/resources/assets/create/models/block/extractor_powered.json @@ -0,0 +1,7 @@ +{ + "parent": "create:block/extractor", + "textures": { + "extractor": "create:block/extractor_powered", + "particle": "create:block/extractor_powered" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/create/models/block/extractor_wireless.json b/src/main/resources/assets/create/models/block/extractor_wireless.json new file mode 100644 index 000000000..0e7a78d33 --- /dev/null +++ b/src/main/resources/assets/create/models/block/extractor_wireless.json @@ -0,0 +1,112 @@ +{ + "__comment": "Model generated using MrCrayfish's Model Creator (https://mrcrayfish.com/tools?id=mc)", + "parent": "block/block", + "textures": { + "redstone_antenna": "create:block/redstone_antenna", + "extractor": "create:block/extractor", + "particle": "create:block/extractor" + }, + "elements": [ + { + "name": "Bottom", + "from": [ 4, 2, -1 ], + "to": [ 12, 3, 5 ], + "faces": { + "east": { "texture": "#extractor", "uv": [ 0, 0, 6, 1 ], "rotation": 180 }, + "south": { "texture": "#extractor", "uv": [ 6, 7, 14, 8 ] }, + "west": { "texture": "#extractor", "uv": [ 0, 0, 6, 1 ] }, + "up": { "texture": "#extractor", "uv": [ 9, 0, 15, 8 ], "rotation": 90 }, + "down": { "texture": "#extractor", "uv": [ 0, 0, 6, 8 ], "rotation": 270 } + } + }, + { + "name": "Top", + "from": [ 4, 9, -1 ], + "to": [ 12, 10, 5 ], + "faces": { + "east": { "texture": "#extractor", "uv": [ 0, 0, 6, 1 ], "rotation": 180 }, + "south": { "texture": "#extractor", "uv": [ 6, 0, 14, 1 ] }, + "west": { "texture": "#extractor", "uv": [ 0, 0, 6, 1 ] }, + "up": { "texture": "#extractor", "uv": [ 0, 0, 6, 8 ], "rotation": 90 }, + "down": { "texture": "#extractor", "uv": [ 9, 0, 15, 8 ], "rotation": 270 } + } + }, + { + "name": "Side", + "from": [ 4, 3, -1 ], + "to": [ 5, 9, 5 ], + "faces": { + "east": { "texture": "#extractor", "uv": [ 9, 1, 15, 7 ], "rotation": 180 }, + "south": { "texture": "#extractor", "uv": [ 6, 1, 7, 7 ] }, + "west": { "texture": "#extractor", "uv": [ 0, 1, 6, 7 ] } + } + }, + { + "name": "Side", + "from": [ 11, 3, -1 ], + "to": [ 12, 9, 5 ], + "faces": { + "east": { "texture": "#extractor", "uv": [ 0, 1, 6, 7 ], "rotation": 180 }, + "south": { "texture": "#extractor", "uv": [ 13, 1, 14, 7 ] }, + "west": { "texture": "#extractor", "uv": [ 9, 1, 15, 7 ] } + } + }, + { + "name": "Center", + "from": [ 5, 3, 3 ], + "to": [ 11, 9, 4 ], + "faces": { + "south": { "texture": "#extractor", "uv": [ 7, 1, 13, 7 ] } + } + }, + { + "name": "FilterSpot", + "from": [ 5, 10, -0.6 ], + "to": [ 11, 12, 4 ], + "rotation": { "origin": [ 8, 11, -1 ], "axis": "x", "angle": 22.5 }, + "faces": { + "north": { "texture": "#extractor", "uv": [ 13, 1, 15, 7 ], "rotation": 90 }, + "east": { "texture": "#extractor", "uv": [ 0.1, 0, 4.7, 2 ], "rotation": 180 }, + "south": { "texture": "#extractor", "uv": [ 4, 1, 5, 7 ], "rotation": 270 }, + "west": { "texture": "#extractor", "uv": [ 0.1, 0, 4.7, 2 ] }, + "up": { "texture": "#extractor", "uv": [ 0, 9, 5, 15 ], "rotation": 90 } + } + }, + { + "name": "AntennaX", + "from": [ 11, 7, 2 ], + "to": [ 14, 17, 3 ], + "faces": { + "north": { "texture": "#redstone_antenna", "uv": [ 0, 0, 3, 10 ] }, + "south": { "texture": "#redstone_antenna", "uv": [ 0, 0, 3, 10 ] }, + "down": { "texture": "#redstone_antenna", "uv": [ 0, 9, 3, 10 ] } + } + }, + { + "name": "AntennaZ", + "from": [ 12, 7, 1 ], + "to": [ 13, 17, 4 ], + "faces": { + "east": { "texture": "#redstone_antenna", "uv": [ 0, 0, 3, 10 ] }, + "west": { "texture": "#redstone_antenna", "uv": [ 0, 0, 3, 10 ] } + } + }, + { + "name": "AntennaTop", + "from": [ 12, 15, 2 ], + "to": [ 13, 16, 3 ], + "faces": { + "up": { "texture": "#redstone_antenna", "uv": [ 1, 1, 2, 2 ] } + } + }, + { + "name": "AntennaDish", + "from": [ 10, 13, 0 ], + "to": [ 15, 13, 5 ], + "faces": { + "up": { "texture": "#redstone_antenna", "uv": [ 4, 0, 9, 5 ] }, + "down": { "texture": "#redstone_antenna", "uv": [ 4, 0, 9, 5 ] } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/create/models/block/extractor_wireless_powered.json b/src/main/resources/assets/create/models/block/extractor_wireless_powered.json new file mode 100644 index 000000000..0291e5e46 --- /dev/null +++ b/src/main/resources/assets/create/models/block/extractor_wireless_powered.json @@ -0,0 +1,8 @@ +{ + "parent": "create:block/extractor_wireless", + "textures": { + "redstone_antenna": "create:block/redstone_antenna_powered", + "extractor": "create:block/extractor_powered", + "particle": "create:block/extractor_powered" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/create/models/block/stockpile_switch.json b/src/main/resources/assets/create/models/block/stockpile_switch.json index c30e2a3a3..3f9ef2344 100644 --- a/src/main/resources/assets/create/models/block/stockpile_switch.json +++ b/src/main/resources/assets/create/models/block/stockpile_switch.json @@ -6,6 +6,7 @@ "brass_casing": "create:block/brass_casing", "dark_oak_planks": "minecraft:block/dark_oak_planks", "iron_block": "minecraft:block/iron_block", + "end": "create:block/stockpile_switch_end", "particle": "create:block/brass_casing" }, "elements": [ @@ -73,7 +74,7 @@ "faces": { "north": { "texture": "#iron_block", "uv": [ 14, 2, 16, 14 ] }, "south": { "texture": "#iron_block", "uv": [ 0, 2, 2, 14 ] }, - "west": { "texture": "#iron_block", "uv": [ 2, 2, 14, 14 ] }, + "west": { "texture": "#end", "uv": [ 2, 2, 14, 14 ] }, "up": { "texture": "#iron_block", "uv": [ 2, 0, 14, 2 ], "rotation": 270 }, "down": { "texture": "#iron_block", "uv": [ 2, 14, 14, 16 ], "rotation": 90 } } diff --git a/src/main/resources/assets/create/models/item/extractor.json b/src/main/resources/assets/create/models/item/extractor.json new file mode 100644 index 000000000..a376a6c3c --- /dev/null +++ b/src/main/resources/assets/create/models/item/extractor.json @@ -0,0 +1,10 @@ +{ + "parent": "create:block/extractor_powered", + "display": { + "gui": { + "rotation": [ 30, 45, 0 ], + "translation": [ 0, 0, 0], + "scale":[ 0.625, 0.625, 0.625 ] + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/create/models/item/filter.json b/src/main/resources/assets/create/models/item/filter.json new file mode 100644 index 000000000..252c20bb5 --- /dev/null +++ b/src/main/resources/assets/create/models/item/filter.json @@ -0,0 +1,8 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "create:item/filter", + "layer1": "create:item/filter_1", + "layer2": "create:item/filter_2" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/create/models/item/linked_extractor.json b/src/main/resources/assets/create/models/item/linked_extractor.json new file mode 100644 index 000000000..c2829e31a --- /dev/null +++ b/src/main/resources/assets/create/models/item/linked_extractor.json @@ -0,0 +1,10 @@ +{ + "parent": "create:block/extractor_wireless_powered", + "display": { + "gui": { + "rotation": [ 30, 45, 0 ], + "translation": [ 0, 0, 0], + "scale":[ 0.625, 0.625, 0.625 ] + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/create/models/item/shop_shelf.json b/src/main/resources/assets/create/models/item/shop_shelf.json index ee3b61f03..889cb576f 100644 --- a/src/main/resources/assets/create/models/item/shop_shelf.json +++ b/src/main/resources/assets/create/models/item/shop_shelf.json @@ -1,3 +1,10 @@ { - "parent": "create:block/shop_shelf" + "parent": "create:block/shop_shelf", + "display": { + "gui": { + "rotation": [ 30, 45, 0 ], + "translation": [ 0, 0, 0], + "scale":[ 0.625, 0.625, 0.625 ] + } + } } \ No newline at end of file diff --git a/src/main/resources/assets/create/textures/block/extractor.png b/src/main/resources/assets/create/textures/block/extractor.png new file mode 100644 index 0000000000000000000000000000000000000000..9ec40f6a7140df09ec57c012445ea1cb285e5e1d GIT binary patch literal 491 zcmVPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!TO+$-MCb06Ha?+Vuj>PIeSL9+vMAABz%XqG z4jHy7w1YMKwrdT&&V%DD4Bc2DBqInD$W-DxO2{do(o{bwPdLt^6IiB+Eix))(v}Iw zHo-oA_bNEf!WjJF8zgBaF$u#(D}pha3{fT{k`k6q2e7X<{KytLaGZs)*x-M~GQ~KI zk;F;|xs9hMppLZvv@uKI>jXk6rHwp<$O^RzJ}Yi6k5%`oi(tQ^E6hB+ystmGgr0*z zOF;gF==b}W_=8!f7198mck+gRvL(7WgTU!H@a=sDQyDVl8?t)>Uh h^Jbx9tZn1}0KW`lr7<7(dkg>o002ovPDHLkV1km1&lCUv literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/extractor_powered.png b/src/main/resources/assets/create/textures/block/extractor_powered.png new file mode 100644 index 0000000000000000000000000000000000000000..d9a84a0ebd3fce03c595688a9f9e52eee231c10c GIT binary patch literal 509 zcmVPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0g_2XK~y+Tm6E?s z0znYQzuh}d6as=dkeK)YbiRPb!rES6!56TzHLb%E^nTN>lb}g0n}0oLr+npI4SD)adB0ngAXVci=6Q7PY!pmAX0P|kS3SM z8U-mSc*Ao994~`XVTIR|u(~yibd^RxL2r;iX@xd&Fa>;fJ}R^-%5K9 z(yoIHdDn6Hzo%h!YZfWvgm0h>kZ2$#v)D(Q1=(tbC{Qp|3a%V&HlqOb;B~Z^fYq&8 z+*TB#PC=p#+WiPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!2kdb!2!6DYwZ940Rc%wK~y+TrIN7< zgfI+-qukwP)e*J_z}ZO`5dzlv4B$ z{_ZcMJE-fLMHq(s9mg@v^UU4^F_7oE2Y)C~6b0*bUD*rEvgpE~>pERPkAMY89LJFp zOarDiySnZE5Nz9)k|d!Z2=)lkFbpIe${0WwKro6T)<}MpC2R2B>{(T;r3*oifDU9% z*%^tj!B;wlHD88Kjwpx;5? z_X-8<9c)nG^c@ItknpypY0Cdh4jo_&v}YcYi?64A73Ven2GIxP*NYAunCn^q0000< KMNUMnLSTZaW|S8I literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/item/filter.png b/src/main/resources/assets/create/textures/item/filter.png new file mode 100644 index 0000000000000000000000000000000000000000..c1bf77f7da2d803e155a3f4eb2b29783fe2957ad GIT binary patch literal 278 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1quc!PTBFjv*HQ$$$R;w`W#u;Pjfz%XW{U$6&@y z!H@A_K^+f2elF*^k+J?qW>3JC_+7Cg$p$=Uh8 zmz6JKF~6Jo)b+^~A0M%nF*_)z9{Od^&dz+aC%MVb>lsd$Dk8c za8ZL{He-(iPf$;{8{>|chVud<4jZ}Mf*&1_K5&46!An|9R7#VdA7}`Jr>mdKI;Vst E0H=T}kN^Mx literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/item/filter_2.png b/src/main/resources/assets/create/textures/item/filter_2.png new file mode 100644 index 0000000000000000000000000000000000000000..bf8d0a23ea6a9ec17265b005bd16dedd3a4318be GIT binary patch literal 173 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucK_^ca#}Etu+aC%MVb>lsdcwnk_ z_<_LYZa2mS87{}B>&LSN?Z_zU literal 0 HcmV?d00001