From 0afb29f9a65a9a54d1b44f56db12b95bc5a01bc3 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Fri, 26 Mar 2021 18:41:03 +0100 Subject: [PATCH 1/4] Simulate and Translocate - Adjusted Brass Tunnels once again to better deal with non-complete item transferrals - Brass tunnels now always output to their sides first - Thrown chromatic products are now gravity-less - Sneaking on Ejectors bypasses them triggering - Fixed ponder tag item listing - Ejectors now trigger observers - Fixed negative bottom pull distance in chutes - Fixed smart chutes deleting non-stackable items - Fixed chutes not able to output partial stacks - Ejectors can now be paused with redstone - Deferred ejector launches by one tick to 'unground' entities more consistently --- .../curiosities/ChromaticCompoundItem.java | 20 +-- .../curiosities/NoGravMagicalDohickyItem.java | 67 +++++++ .../curiosities/RefinedRadianceItem.java | 48 +---- .../content/curiosities/ShadowSteelItem.java | 50 ++---- .../belts/tunnel/BrassTunnelTileEntity.java | 170 ++++++++++++------ .../block/chute/ChuteTileEntity.java | 158 ++++++++-------- .../logistics/block/depot/EjectorBlock.java | 15 +- .../block/depot/EjectorTileEntity.java | 89 ++++++--- .../block/depot/EjectorTriggerPacket.java | 2 +- .../ponder/content/PonderTagScreen.java | 2 +- 10 files changed, 372 insertions(+), 249 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/curiosities/NoGravMagicalDohickyItem.java diff --git a/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundItem.java b/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundItem.java index 4b853139a..d50cbc3ad 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundItem.java @@ -89,7 +89,7 @@ public class ChromaticCompoundItem extends Item { if (y < 0 && y - yMotion < -10 && config.enableShadowSteelRecipe.get()) { ItemStack newStack = AllItems.SHADOW_STEEL.asStack(); newStack.setCount(stack.getCount()); - data.putBoolean("FromVoid", true); + data.putBoolean("JustCreated", true); entity.setItem(newStack); } @@ -102,7 +102,7 @@ public class ChromaticCompoundItem extends Item { ItemEntity newEntity = new ItemEntity(world, entity.getX(), entity.getY(), entity.getZ(), newStack); newEntity.setMotion(entity.getMotion()); newEntity.getPersistentData() - .putBoolean("FromLight", true); + .putBoolean("JustCreated", true); itemData.remove("CollectingLight"); world.addEntity(newEntity); @@ -119,10 +119,8 @@ public class ChromaticCompoundItem extends Item { int entityZ = MathHelper.floor(entity.getZ()); int localWorldHeight = world.getHeight(Heightmap.Type.WORLD_SURFACE, entityX, entityZ); - BlockPos.Mutable testPos = new BlockPos.Mutable( - entityX, - Math.min(MathHelper.floor(entity.getY()), localWorldHeight), - entityZ); + BlockPos.Mutable testPos = + new BlockPos.Mutable(entityX, Math.min(MathHelper.floor(entity.getY()), localWorldHeight), entityZ); while (testPos.getY() > 0) { testPos.move(Direction.DOWN); @@ -131,12 +129,14 @@ public class ChromaticCompoundItem extends Item { break; if (state.getBlock() == Blocks.BEACON) { TileEntity te = world.getTileEntity(testPos); - - if (!(te instanceof BeaconTileEntity)) break; + + if (!(te instanceof BeaconTileEntity)) + break; BeaconTileEntity bte = (BeaconTileEntity) te; - if (bte.getLevels() != 0 && !bte.beamSegments.isEmpty()) isOverBeacon = true; + if (bte.getLevels() != 0 && !bte.beamSegments.isEmpty()) + isOverBeacon = true; break; } @@ -145,7 +145,7 @@ public class ChromaticCompoundItem extends Item { if (isOverBeacon) { ItemStack newStack = AllItems.REFINED_RADIANCE.asStack(); newStack.setCount(stack.getCount()); - data.putBoolean("FromLight", true); + data.putBoolean("JustCreated", true); entity.setItem(newStack); return false; diff --git a/src/main/java/com/simibubi/create/content/curiosities/NoGravMagicalDohickyItem.java b/src/main/java/com/simibubi/create/content/curiosities/NoGravMagicalDohickyItem.java new file mode 100644 index 000000000..bf9585a68 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/curiosities/NoGravMagicalDohickyItem.java @@ -0,0 +1,67 @@ +package com.simibubi.create.content.curiosities; + +import com.simibubi.create.foundation.utility.VecHelper; + +import net.minecraft.entity.item.ItemEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.particles.ParticleTypes; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class NoGravMagicalDohickyItem extends Item { + + public NoGravMagicalDohickyItem(Properties p_i48487_1_) { + super(p_i48487_1_); + } + + @Override + public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) { + World world = entity.world; + Vec3d pos = entity.getPositionVec(); + CompoundNBT persistentData = entity.getPersistentData(); + + if (world.isRemote) { + if (world.rand.nextFloat() < getIdleParticleChance(entity)) { + Vec3d ppos = VecHelper.offsetRandomly(pos, world.rand, .5f); + world.addParticle(ParticleTypes.END_ROD, ppos.x, pos.y, ppos.z, 0, -.1f, 0); + } + + if (entity.isSilent() && !persistentData.getBoolean("PlayEffects")) { + Vec3d basemotion = new Vec3d(0, 1, 0); + world.addParticle(ParticleTypes.FLASH, pos.x, pos.y, pos.z, 0, 0, 0); + for (int i = 0; i < 20; i++) { + Vec3d motion = VecHelper.offsetRandomly(basemotion, world.rand, 1); + world.addParticle(ParticleTypes.WITCH, pos.x, pos.y, pos.z, motion.x, motion.y, motion.z); + world.addParticle(ParticleTypes.END_ROD, pos.x, pos.y, pos.z, motion.x, motion.y, motion.z); + } + persistentData.putBoolean("PlayEffects", true); + } + + return false; + } + + entity.setNoGravity(true); + + if (!persistentData.contains("JustCreated")) + return false; + onCreated(entity, persistentData); + return false; + } + + protected float getIdleParticleChance(ItemEntity entity) { + return MathHelper.clamp(entity.getItem() + .getCount() - 10, 5, 100) / 64f; + } + + protected void onCreated(ItemEntity entity, CompoundNBT persistentData) { + entity.lifespan = 6000; + persistentData.remove("JustCreated"); + + // just a flag to tell the client to play an effect + entity.setSilent(true); + } + +} diff --git a/src/main/java/com/simibubi/create/content/curiosities/RefinedRadianceItem.java b/src/main/java/com/simibubi/create/content/curiosities/RefinedRadianceItem.java index 32b5a6e98..c853d6be7 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/RefinedRadianceItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/RefinedRadianceItem.java @@ -1,59 +1,25 @@ package com.simibubi.create.content.curiosities; -import com.simibubi.create.foundation.utility.VecHelper; - import net.minecraft.entity.item.ItemEntity; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.particles.ParticleTypes; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.World; +import net.minecraft.nbt.CompoundNBT; -public class RefinedRadianceItem extends Item { +public class RefinedRadianceItem extends NoGravMagicalDohickyItem { public RefinedRadianceItem(Properties properties) { super(properties); } - + @Override public boolean hasEffect(ItemStack stack) { return true; } @Override - public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) { - World world = entity.world; - Vec3d pos = entity.getPositionVec(); - - if (world.isRemote && entity.hasNoGravity()) { - if (world.rand.nextFloat() < MathHelper.clamp(entity.getItem().getCount() - 10, 1, 100) / 64f) { - Vec3d ppos = VecHelper.offsetRandomly(pos, world.rand, .5f); - world.addParticle(ParticleTypes.END_ROD, ppos.x, pos.y, ppos.z, 0, -.1f, 0); - } - - if (!entity.getPersistentData().contains("ClientAnimationPlayed")) { - Vec3d basemotion = new Vec3d(0, 1, 0); - world.addParticle(ParticleTypes.FLASH, pos.x, pos.y, pos.z, 0, 0, 0); - for (int i = 0; i < 20; i++) { - Vec3d motion = VecHelper.offsetRandomly(basemotion, world.rand, 1); - world.addParticle(ParticleTypes.WITCH, pos.x, pos.y, pos.z, motion.x, motion.y, motion.z); - world.addParticle(ParticleTypes.END_ROD, pos.x, pos.y, pos.z, motion.x, motion.y, motion.z); - } - entity.getPersistentData().putBoolean("ClientAnimationPlayed", true); - } - - return false; - } - - if (!entity.getPersistentData().contains("FromLight")) - return false; - - entity.lifespan = 6000; - entity.setNoGravity(true); - entity.setMotion(entity.getMotion().add(0, .15f, 0)); - entity.getPersistentData().remove("FromLight"); - return false; + protected void onCreated(ItemEntity entity, CompoundNBT persistentData) { + super.onCreated(entity, persistentData); + entity.setMotion(entity.getMotion() + .add(0, .15f, 0)); } } diff --git a/src/main/java/com/simibubi/create/content/curiosities/ShadowSteelItem.java b/src/main/java/com/simibubi/create/content/curiosities/ShadowSteelItem.java index 5508f5e1d..007e0f627 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/ShadowSteelItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/ShadowSteelItem.java @@ -1,56 +1,26 @@ package com.simibubi.create.content.curiosities; -import com.simibubi.create.foundation.utility.VecHelper; - import net.minecraft.entity.item.ItemEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.particles.ParticleTypes; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.World; -public class ShadowSteelItem extends Item { +public class ShadowSteelItem extends NoGravMagicalDohickyItem { public ShadowSteelItem(Properties properties) { super(properties); } @Override - public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) { - World world = entity.world; - Vec3d pos = entity.getPositionVec(); - - if (world.isRemote && entity.hasNoGravity()) { - if (world.rand.nextFloat() < MathHelper.clamp(entity.getItem().getCount() - 10, - Math.min(entity.getMotion().y * 20, 20), 100) / 64f) { - Vec3d ppos = VecHelper.offsetRandomly(pos, world.rand, .5f); - world.addParticle(ParticleTypes.END_ROD, ppos.x, pos.y, ppos.z, 0, -.1f, 0); - } - - if (!entity.getPersistentData().contains("ClientAnimationPlayed")) { - Vec3d basemotion = new Vec3d(0, 1, 0); - world.addParticle(ParticleTypes.FLASH, pos.x, pos.y, pos.z, 0, 0, 0); - for (int i = 0; i < 20; i++) { - Vec3d motion = VecHelper.offsetRandomly(basemotion, world.rand, 1); - world.addParticle(ParticleTypes.WITCH, pos.x, pos.y, pos.z, motion.x, motion.y, motion.z); - world.addParticle(ParticleTypes.END_ROD, pos.x, pos.y, pos.z, motion.x, motion.y, motion.z); - } - entity.getPersistentData().putBoolean("ClientAnimationPlayed", true); - } - - return false; - } - - if (!entity.getPersistentData().contains("FromVoid")) - return false; - - entity.setNoGravity(true); + protected void onCreated(ItemEntity entity, CompoundNBT persistentData) { + super.onCreated(entity, persistentData); float yMotion = (entity.fallDistance + 3) / 50f; entity.setMotion(0, yMotion, 0); - entity.lifespan = 6000; - entity.getPersistentData().remove("FromVoid"); - return false; + } + + @Override + protected float getIdleParticleChance(ItemEntity entity) { + return (float) (MathHelper.clamp(entity.getItem() + .getCount() - 10, MathHelper.clamp(entity.getMotion().y * 20, 5, 20), 100) / 64f); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelTileEntity.java index 36c76bbe9..f24f86018 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelTileEntity.java @@ -2,7 +2,10 @@ package com.simibubi.create.content.logistics.block.belts.tunnel; import java.util.ArrayList; import java.util.HashSet; +import java.util.IdentityHashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.Random; import java.util.Set; @@ -188,12 +191,17 @@ public class BrassTunnelTileEntity extends BeltTunnelTileEntity { } private static Random rand = new Random(); + private static Map, ItemStack> distributed = new IdentityHashMap<>(); + private static Set> full = new HashSet<>(); private void distribute(List> validTargets) { int amountTargets = validTargets.size(); if (amountTargets == 0) return; + distributed.clear(); + full.clear(); + int indexStart = previousOutputIndex % amountTargets; SelectionMode mode = selectionMode.get(); boolean force = mode == SelectionMode.FORCED_ROUND_ROBIN || mode == SelectionMode.FORCED_SPLIT; @@ -204,55 +212,94 @@ public class BrassTunnelTileEntity extends BeltTunnelTileEntity { if (mode == SelectionMode.PREFER_NEAREST || mode == SelectionMode.SYNCHRONIZE) indexStart = 0; - ItemStack toDistribute = null; - int leftovers = 0; - int remainingOutputs = amountTargets; + ItemStack toDistribute = stackToDistribute.copy(); + for (boolean distributeAgain : Iterate.trueAndFalse) { + ItemStack toDistributeThisCycle = null; + int remainingOutputs = amountTargets; + int leftovers = 0; - for (boolean simulate : Iterate.trueAndFalse) { - if (remainingOutputs == 0) - return; - - leftovers = 0; - int index = indexStart; - int stackSize = stackToDistribute.getCount(); - int splitStackSize = stackSize / remainingOutputs; - int splitRemainder = stackSize % remainingOutputs; - int visited = 0; + for (boolean simulate : Iterate.trueAndFalse) { + if (remainingOutputs == 0) + break; - toDistribute = stackToDistribute.copy(); - if (!(force || split) && simulate) - continue; - - while (visited < amountTargets) { - Pair pair = validTargets.get(index); - BrassTunnelTileEntity tunnel = pair.getKey(); - Direction side = pair.getValue(); - index = (index + 1) % amountTargets; - visited++; + leftovers = 0; + int index = indexStart; + int stackSize = toDistribute.getCount(); + int splitStackSize = stackSize / remainingOutputs; + int splitRemainder = stackSize % remainingOutputs; + int visited = 0; - int count = split ? splitStackSize + (splitRemainder > 0 ? 1 : 0) : stackSize; - ItemStack toOutput = ItemHandlerHelper.copyStackWithSize(toDistribute, count); - ItemStack remainder = insertIntoTunnel(tunnel, side, toOutput, simulate); - - if (remainder == null || remainder.getCount() == count) { - if (force) - return; - if (split && simulate) - remainingOutputs--; + toDistributeThisCycle = toDistribute.copy(); + if (!(force || split) && simulate) continue; - } - leftovers += remainder.getCount(); - toDistribute.shrink(count); - if (toDistribute.isEmpty()) - break; - splitRemainder--; - if (!split) - break; + while (visited < amountTargets) { + Pair pair = validTargets.get(index); + BrassTunnelTileEntity tunnel = pair.getKey(); + Direction side = pair.getValue(); + index = (index + 1) % amountTargets; + visited++; + + if (full.contains(pair)) { + if (split && simulate) + remainingOutputs--; + continue; + } + + int count = split ? splitStackSize + (splitRemainder > 0 ? 1 : 0) : stackSize; + ItemStack toOutput = ItemHandlerHelper.copyStackWithSize(toDistributeThisCycle, count); + + // Grow by 1 to determine if target is full even after a successful transfer + boolean testWithIncreasedCount = distributed.containsKey(pair); + int increasedCount = testWithIncreasedCount ? distributed.get(pair) + .getCount() : 0; + if (testWithIncreasedCount) + toOutput.grow(increasedCount); + + ItemStack remainder = insertIntoTunnel(tunnel, side, toOutput, true); + + if (remainder == null || remainder.getCount() == (testWithIncreasedCount ? count + 1 : count)) { + if (force) + return; + if (split && simulate) + remainingOutputs--; + if (!simulate) + full.add(pair); + continue; + } else if (!remainder.isEmpty() && !simulate) { + full.add(pair); + } + + if (!simulate) { + toOutput.shrink(remainder.getCount()); + distributed.put(pair, toOutput); + } + + leftovers += remainder.getCount(); + toDistributeThisCycle.shrink(count); + if (toDistributeThisCycle.isEmpty()) + break; + splitRemainder--; + if (!split) + break; + } } + + toDistribute.setCount(toDistributeThisCycle.getCount() + leftovers); + if (leftovers == 0 && distributeAgain) + break; + if (!split) + break; } - stackToDistribute = ItemHandlerHelper.copyStackWithSize(stackToDistribute, toDistribute.getCount() + leftovers); + int failedTransferrals = 0; + for (Entry, ItemStack> entry : distributed.entrySet()) { + Pair pair = entry.getKey(); + failedTransferrals += insertIntoTunnel(pair.getKey(), pair.getValue(), entry.getValue(), false).getCount(); + } + + toDistribute.grow(failedTransferrals); + stackToDistribute = ItemHandlerHelper.copyStackWithSize(stackToDistribute, toDistribute.getCount()); previousOutputIndex++; previousOutputIndex %= amountTargets; notifyUpdate(); @@ -418,25 +465,34 @@ public class BrassTunnelTileEntity extends BeltTunnelTileEntity { if (!AllBlocks.BRASS_TUNNEL.has(blockState)) return; - for (Direction direction : Iterate.horizontalDirections) { - if (direction == movementFacing && below.getSpeed() == 0) + boolean prioritizeSides = tunnelTE == this; + + for (boolean sidePass : Iterate.trueAndFalse) { + if (!prioritizeSides && sidePass) continue; - if (direction == movementFacing.getOpposite()) - continue; - if (tunnelTE.sides.contains(direction)) { - BlockPos offset = tunnelTE.pos.down() - .offset(direction); - DirectBeltInputBehaviour inputBehaviour = - TileEntityBehaviour.get(world, offset, DirectBeltInputBehaviour.TYPE); - if (inputBehaviour == null) { - if (direction == movementFacing) - if (!Block.hasSolidSide(world.getBlockState(offset), world, offset, direction.getOpposite())) - validOutputs.add(Pair.of(tunnelTE, direction)); + for (Direction direction : Iterate.horizontalDirections) { + if (direction == movementFacing && below.getSpeed() == 0) + continue; + if (prioritizeSides && sidePass == (direction.getAxis() == movementFacing.getAxis())) + continue; + if (direction == movementFacing.getOpposite()) + continue; + if (tunnelTE.sides.contains(direction)) { + BlockPos offset = tunnelTE.pos.down() + .offset(direction); + DirectBeltInputBehaviour inputBehaviour = + TileEntityBehaviour.get(world, offset, DirectBeltInputBehaviour.TYPE); + if (inputBehaviour == null) { + if (direction == movementFacing) + if (!Block.hasSolidSide(world.getBlockState(offset), world, offset, + direction.getOpposite())) + validOutputs.add(Pair.of(tunnelTE, direction)); + continue; + } + if (inputBehaviour.canInsertFromSide(direction)) + validOutputs.add(Pair.of(tunnelTE, direction)); continue; } - if (inputBehaviour.canInsertFromSide(direction)) - validOutputs.add(Pair.of(tunnelTE, direction)); - continue; } } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java index 408907020..9b21c5b09 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.logistics.block.chute; import java.util.LinkedList; import java.util.List; +import java.util.function.Predicate; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; @@ -61,7 +62,7 @@ import net.minecraftforge.items.ItemHandlerHelper; */ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInformation { // , IAirCurrentSource { -// public AirCurrent airCurrent; + // public AirCurrent airCurrent; float pull; float push; @@ -92,7 +93,7 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor capAbove = LazyOptional.empty(); capBelow = LazyOptional.empty(); bottomPullDistance = 0; -// airCurrent = new AirCurrent(this); + // airCurrent = new AirCurrent(this); updateAirFlow = true; } @@ -178,7 +179,7 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor private void updateAirFlow(float itemSpeed) { updateAirFlow = false; -// airCurrent.rebuild(); + // airCurrent.rebuild(); if (itemSpeed > 0 && world != null && !world.isRemote) { float speed = pull - push; beltBelow = null; @@ -208,14 +209,14 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor beltBelowOffset = i - 1; break; } - this.bottomPullDistance = flowLimit; + this.bottomPullDistance = Math.max(0, flowLimit); } sendData(); } private void findEntities(float itemSpeed) { -// if (getSpeed() != 0) -// airCurrent.findEntities(); + // if (getSpeed() != 0) + // airCurrent.findEntities(); if (bottomPullDistance <= 0 && !getItem().isEmpty() || itemSpeed <= 0 || world == null || world.isRemote) return; if (!canCollectItemsFromBelow()) @@ -267,8 +268,8 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor } extractFromBelt(itemSpeed); -// if (getSpeed() != 0) -// airCurrent.tick(); + // if (getSpeed() != 0) + // airCurrent.tick(); } public void blockBelowChanged() { @@ -323,29 +324,40 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor private void handleInputFromAbove() { if (!capAbove.isPresent()) capAbove = grabCapability(Direction.UP); - if (capAbove.isPresent()) { - int count = getExtractionAmount(); - if (count == 0) - item = - ItemHelper.extract(capAbove.orElse(null), this::canAcceptItem, ExtractionCountMode.UPTO, 16, false); - else - item = ItemHelper.extract(capAbove.orElse(null), this::canAcceptItem, ExtractionCountMode.EXACTLY, - count, false); + if (!capAbove.isPresent()) + return; + + int count = getExtractionAmount(); + IItemHandler inv = capAbove.orElse(null); + Predicate canAccept = this::canAcceptItem; + if (count == 0) { + item = ItemHelper.extract(inv, canAccept, ExtractionCountMode.UPTO, 16, false); + return; } + + if (!ItemHelper.extract(inv, canAccept, ExtractionCountMode.EXACTLY, count, true) + .isEmpty()) + item = ItemHelper.extract(inv, canAccept, ExtractionCountMode.EXACTLY, count, false); } private void handleInputFromBelow() { if (!capBelow.isPresent()) capBelow = grabCapability(Direction.DOWN); - if (capBelow.isPresent()) { - int count = getExtractionAmount(); - if (count == 0) - item = - ItemHelper.extract(capBelow.orElse(null), this::canAcceptItem, ExtractionCountMode.UPTO, 16, false); - else - item = ItemHelper.extract(capBelow.orElse(null), this::canAcceptItem, ExtractionCountMode.EXACTLY, - count, false); + if (!capBelow.isPresent()) + return; + + int count = getExtractionAmount(); + IItemHandler inv = capBelow.orElse(null); + Predicate canAccept = this::canAcceptItem; + + if (count == 0) { + item = ItemHelper.extract(inv, canAccept, ExtractionCountMode.UPTO, 16, false); + return; } + + if (!ItemHelper.extract(inv, canAccept, ExtractionCountMode.EXACTLY, count, true) + .isEmpty()) + item = ItemHelper.extract(inv, canAccept, ExtractionCountMode.EXACTLY, count, false); } private boolean handleDownwardOutput(boolean simulate) { @@ -359,9 +371,10 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor capBelow = grabCapability(Direction.DOWN); if (capBelow.isPresent()) { ItemStack remainder = ItemHandlerHelper.insertItemStacked(capBelow.orElse(null), item, simulate); + ItemStack held = getItem(); if (!simulate) setItem(remainder); - if (remainder.isEmpty()) + if (remainder.getCount() != held.getCount()) return true; if (direction == Direction.DOWN) return false; @@ -409,10 +422,11 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor if (!capAbove.isPresent()) capAbove = grabCapability(Direction.UP); if (capAbove.isPresent()) { + int countBefore = item.getCount(); ItemStack remainder = ItemHandlerHelper.insertItemStacked(capAbove.orElse(null), item, simulate); if (!simulate) - setItem(ItemStack.EMPTY); - return remainder.isEmpty(); + item = remainder; + return countBefore != remainder.getCount(); } } @@ -521,8 +535,8 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor super.read(compound, clientPacket); -// if (clientPacket) -// airCurrent.rebuild(); + // if (clientPacket) + // airCurrent.rebuild(); if (hasWorld() && world != null && world.isRemote && !previousItem.equals(item, false) && !item.isEmpty()) { if (world.rand.nextInt(3) != 0) @@ -718,47 +732,47 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor return item; } -// @Override -// @Nullable -// public AirCurrent getAirCurrent() { -// return airCurrent; -// } -// -// @Nullable -// @Override -// public World getAirCurrentWorld() { -// return world; -// } -// -// @Override -// public BlockPos getAirCurrentPos() { -// return pos; -// } -// -// @Override -// public float getSpeed() { -// if (getBlockState().get(ChuteBlock.SHAPE) == Shape.NORMAL && getBlockState().get(ChuteBlock.FACING) != Direction.DOWN) -// return 0; -// return pull + push; -// } -// -// @Override -// @Nullable -// public Direction getAirFlowDirection() { -// float speed = getSpeed(); -// if (speed == 0) -// return null; -// return speed > 0 ? Direction.UP : Direction.DOWN; -// } -// -// @Override -// public boolean isSourceRemoved() { -// return removed; -// } -// -// @Override -// public Direction getAirflowOriginSide() { -// return world != null && !(world.getTileEntity(pos.down()) instanceof IAirCurrentSource) -// && getBlockState().get(ChuteBlock.FACING) == Direction.DOWN ? Direction.DOWN : Direction.UP; -// } + // @Override + // @Nullable + // public AirCurrent getAirCurrent() { + // return airCurrent; + // } + // + // @Nullable + // @Override + // public World getAirCurrentWorld() { + // return world; + // } + // + // @Override + // public BlockPos getAirCurrentPos() { + // return pos; + // } + // + // @Override + // public float getSpeed() { + // if (getBlockState().get(ChuteBlock.SHAPE) == Shape.NORMAL && getBlockState().get(ChuteBlock.FACING) != Direction.DOWN) + // return 0; + // return pull + push; + // } + // + // @Override + // @Nullable + // public Direction getAirFlowDirection() { + // float speed = getSpeed(); + // if (speed == 0) + // return null; + // return speed > 0 ? Direction.UP : Direction.DOWN; + // } + // + // @Override + // public boolean isSourceRemoved() { + // return removed; + // } + // + // @Override + // public Direction getAirflowOriginSide() { + // return world != null && !(world.getTileEntity(pos.down()) instanceof IAirCurrentSource) + // && getBlockState().get(ChuteBlock.FACING) == Direction.DOWN ? Direction.DOWN : Direction.UP; + // } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorBlock.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorBlock.java index 25b289876..ed00513f0 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorBlock.java @@ -12,6 +12,7 @@ import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.utility.VecHelper; +import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.item.ItemEntity; @@ -49,10 +50,16 @@ public class EjectorBlock extends HorizontalKineticBlock implements ITE tileEntityOptional = getTileEntityOptional(p_180658_1_, p_180658_2_); - if (tileEntityOptional.isPresent()) { + if (tileEntityOptional.isPresent() && !p_180658_3_.bypassesLandingEffects()) { p_180658_3_.handleFallDamage(p_180658_4_, 0.0F); return; } @@ -67,6 +74,8 @@ public class EjectorBlock extends HorizontalKineticBlock implements ITE(); + powered = false; } @Override @@ -92,10 +95,24 @@ public class EjectorTileEntity extends KineticTileEntity { depotBehaviour.addSubBehaviours(behaviours); } - public void launchAll() { - if (state != State.CHARGED && !(world.isRemote && state == State.LAUNCHING)) - return; + @Override + public void initialize() { + super.initialize(); + updateSignal(); + } + public void activate() { + launch = true; + nudgeEntities(); + } + + protected boolean cannotLaunch() { + return state != State.CHARGED && !(world.isRemote && state == State.LAUNCHING); + } + + public void activateDeferred() { + if (cannotLaunch()) + return; Direction facing = getFacing(); List entities = world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(pos).grow(-1 / 16f, 0, -1 / 16f)); @@ -135,12 +152,11 @@ public class EjectorTileEntity extends KineticTileEntity { AllPackets.channel.sendToServer(new EjectorElytraPacket(pos)); } - lidProgress.chase(1, .8f, Chaser.EXP); - state = State.LAUNCHING; - if (!world.isRemote) { - world.playSound(null, pos, SoundEvents.BLOCK_WOODEN_TRAPDOOR_CLOSE, SoundCategory.BLOCKS, .5f, 1f); - world.playSound(null, pos, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, .125f, 1.4f); + lidProgress.chase(1, .8f, Chaser.EXP); + state = State.LAUNCHING; + world.playSound(null, pos, SoundEvents.BLOCK_WOODEN_TRAPDOOR_CLOSE, SoundCategory.BLOCKS, .35f, 1f); + world.playSound(null, pos, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, .1f, 1.4f); } } @@ -187,6 +203,9 @@ public class EjectorTileEntity extends KineticTileEntity { return; } + if (!world.isRemote) + world.markAndNotifyBlock(pos, world.getChunkAt(pos), getBlockState(), getBlockState(), 0); + if (depotBehaviour.heldItem != null) { launchedItems.add(IntAttached.withZero(heldItemStack)); depotBehaviour.removeHeldItem(); @@ -218,9 +237,13 @@ public class EjectorTileEntity extends KineticTileEntity { boolean doLogic = !world.isRemote || isVirtual(); State prevState = state; - float maxTime = Math.max(3, (float) launcher.getTotalFlyingTicks()); + if (launch) { + launch = false; + activateDeferred(); + } + for (Iterator> iterator = launchedItems.iterator(); iterator.hasNext();) { IntAttached intAttached = iterator.next(); if (intAttached.exceeds((int) maxTime)) { @@ -241,11 +264,19 @@ public class EjectorTileEntity extends KineticTileEntity { if (state == State.CHARGED) { lidProgress.setValue(0); + lidProgress.updateChaseSpeed(0); if (doLogic) ejectIfTriggered(); } if (state == State.RETRACTING) { + lidProgress.updateChaseSpeed(0); + if (lidProgress.getValue() == 0 && doLogic) { + state = State.CHARGED; + lidProgress.setValue(0); + sendData(); + } + float value = MathHelper.clamp(lidProgress.getValue() - getWindUpSpeed(), 0, 1); lidProgress.setValue(value); @@ -255,24 +286,22 @@ public class EjectorTileEntity extends KineticTileEntity { if (((int) world.getGameTime()) % soundRate == 0 && doLogic) world.playSound(null, pos, SoundEvents.BLOCK_WOODEN_BUTTON_CLICK_OFF, SoundCategory.BLOCKS, volume, pitch); - - if (lidProgress.getValue() == 0 && doLogic) { - state = State.CHARGED; - lidProgress.setValue(0); - - List entities = - world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(pos).grow(-1 / 16f, 0, -1 / 16f)); - for (Entity entity : entities) - if (!(entity instanceof PlayerEntity)) - entity.setPosition(entity.getX(), entity.getY() + volume, entity.getZ()); - } } if (state != prevState) notifyUpdate(); } + protected void nudgeEntities() { + for (Entity entity : world.getEntitiesWithinAABB(Entity.class, + new AxisAlignedBB(pos).grow(-1 / 16f, 0, -1 / 16f))) + if (!(entity instanceof PlayerEntity)) + entity.setPosition(entity.getX(), entity.getY() + .125f, entity.getZ()); + } + protected void ejectIfTriggered() { + if (powered) + return; int presentStackSize = depotBehaviour.getPresentStackSize(); if (presentStackSize == 0) return; @@ -280,11 +309,11 @@ public class EjectorTileEntity extends KineticTileEntity { return; Direction funnelFacing = getFacing().getOpposite(); + ItemStack held = depotBehaviour.getHeldItemStack(); if (AbstractFunnelBlock.getFunnelFacing(world.getBlockState(pos.up())) == funnelFacing) { DirectBeltInputBehaviour directOutput = getBehaviour(DirectBeltInputBehaviour.TYPE); if (depotBehaviour.heldItem != null) { - ItemStack tryFunnel = - directOutput.tryExportingToBeltFunnel(depotBehaviour.getHeldItemStack(), funnelFacing, true); + ItemStack tryFunnel = directOutput.tryExportingToBeltFunnel(held, funnelFacing, true); if (tryFunnel == null || !tryFunnel.isEmpty()) return; } @@ -294,11 +323,11 @@ public class EjectorTileEntity extends KineticTileEntity { // Do not eject if target cannot accept held item if (targetOpenInv != null && depotBehaviour.heldItem != null - && targetOpenInv.handleInsertion(depotBehaviour.getHeldItemStack(), Direction.UP, true) - .isItemEqual(depotBehaviour.getHeldItemStack())) + && targetOpenInv.handleInsertion(held, Direction.UP, true) + .getCount() == held.getCount()) return; - launchAll(); + activate(); notifyUpdate(); } @@ -368,6 +397,7 @@ public class EjectorTileEntity extends KineticTileEntity { super.write(compound, clientPacket); compound.putInt("HorizontalDistance", launcher.getHorizontalDistance()); compound.putInt("VerticalDistance", launcher.getVerticalDistance()); + compound.putBoolean("Powered", powered); NBTHelper.writeEnum(compound, "State", state); compound.put("Lid", lidProgress.writeNBT()); compound.put("LaunchedItems", @@ -386,12 +416,21 @@ public class EjectorTileEntity extends KineticTileEntity { launcher.clamp(AllConfigs.SERVER.kinetics.maxEjectorDistance.get()); } + powered = compound.getBoolean("Powered"); state = NBTHelper.readEnum(compound, "State", State.class); lidProgress.readNBT(compound.getCompound("Lid"), clientPacket); launchedItems = NBTHelper.readCompoundList(compound.getList("LaunchedItems", NBT.TAG_COMPOUND), nbt -> IntAttached.read(nbt, ItemStack::read)); } + public void updateSignal() { + boolean shoudPower = world.isBlockPowered(pos); + if (shoudPower == powered) + return; + powered = shoudPower; + sendData(); + } + public void setTarget(int horizontalDistance, int verticalDistance) { launcher.set(Math.max(1, horizontalDistance), verticalDistance); if (horizontalDistance == 0 && verticalDistance == 0) { diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorTriggerPacket.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorTriggerPacket.java index fa9dd6a5e..09f288fec 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorTriggerPacket.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorTriggerPacket.java @@ -23,7 +23,7 @@ public class EjectorTriggerPacket extends TileEntityConfigurationPacket tag.getMainItem() .isEmpty() - || tag.getMainItem() + || !tag.getMainItem() .getItem() .getRegistryName() .equals(rl)) From cb759e793e84d408f77e641782e3e43dfcd7f534 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Fri, 26 Mar 2021 22:05:16 +0100 Subject: [PATCH 2/4] 3D Printing is cool again - Fixed Schematicannon clearing blocks outside of a Schematics' bounding box - Safety check for onBlockPlacedBy with null player - Deployers with a positioned Schematic as their filter will place blocks accordingly, taking items from the contraption inventory --- src/generated/resources/.cache/cache | 14 +- .../assets/create/blockstates/fluid_pipe.json | 154 +++++++++--------- .../create/blockstates/radial_chassis.json | 24 +-- .../resources/assets/create/lang/en_us.json | 8 +- .../assets/create/lang/unfinished/de_de.json | 2 +- .../assets/create/lang/unfinished/es_mx.json | 8 +- .../assets/create/lang/unfinished/nl_nl.json | 2 +- .../assets/create/lang/unfinished/pt_br.json | 2 +- .../deployer/DeployerMovementBehaviour.java | 90 +++++++++- .../schematics/block/LaunchedItem.java | 52 +----- .../block/SchematicannonTileEntity.java | 49 +++--- .../schematics/client/SchematicHandler.java | 6 +- .../foundation/utility/BlockHelper.java | 72 +++++++- .../assets/create/lang/default/messages.json | 8 +- 14 files changed, 301 insertions(+), 190 deletions(-) diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index a14f23093..a7ed66061 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -140,7 +140,7 @@ de8a40b7daf1497d5aecee47a43b3e0b1d030b00 assets/create/blockstates/fancy_scoria_ fc9ac0a7e7191b93516719455a17177fa6524ecc assets/create/blockstates/fancy_weathered_limestone_bricks_slab.json b2a7c321b1795f20e7433f81a55ce4683de081b8 assets/create/blockstates/fancy_weathered_limestone_bricks_stairs.json 6372fe02ba0065acb0758121c45a15a1a8fdc5de assets/create/blockstates/fancy_weathered_limestone_bricks_wall.json -3d97226b5e8d8f70ed08e45e78db1faf78d5e28b assets/create/blockstates/fluid_pipe.json +48086bf71a824faf14841b698050cc8544b09a9b assets/create/blockstates/fluid_pipe.json f0eaab18e16c4f3f65ebf3b55b08f0dc445720fe assets/create/blockstates/fluid_tank.json 5408d92ab02af86539ac42971d4033545970bb3a assets/create/blockstates/fluid_valve.json e9da1794b6ece7f9aa8bcb43d42c23a55446133b assets/create/blockstates/flywheel.json @@ -337,7 +337,7 @@ e8b0a401c10d1ba67ed71ba31bd5f9bc28571b65 assets/create/blockstates/powered_toggl d06cd9a1101b18d306a786320aab12018b1325d6 assets/create/blockstates/purple_sail.json 92957119abd5fbcca36a113b2a80255fd70fc303 assets/create/blockstates/purple_seat.json 61035f8afe75ff7bbd291da5d8690bcbebe679eb assets/create/blockstates/purple_valve_handle.json -8d7e653bfd9846e684a0d3725595714a19201017 assets/create/blockstates/radial_chassis.json +6fa36883e76e9e403bb429c8f86b8c0d3bba0cff assets/create/blockstates/radial_chassis.json 45877c4d90a7185c2f304edbd67379d800920439 assets/create/blockstates/red_sail.json da1b08387af7afa0855ee8d040f620c01f20660a assets/create/blockstates/red_seat.json 722fc77bbf387af8a4016e42cbf9501d2b968881 assets/create/blockstates/red_valve_handle.json @@ -403,16 +403,16 @@ a3a11524cd3515fc01d905767b4b7ea782adaf03 assets/create/blockstates/yellow_seat.j 7f39521b211441f5c3e06d60c5978cebe16cacfb assets/create/blockstates/zinc_block.json b7181bcd8182b2f17088e5aa881f374c9c65470c assets/create/blockstates/zinc_ore.json ce0e5405da381a86625b908c569c5dbe347abdba assets/create/lang/en_ud.json -e572959e40b9917e88e6b86b5b9ebbf091d5f1ba assets/create/lang/en_us.json -6d55a1325fc8bf894b92285f217b794e32575739 assets/create/lang/unfinished/de_de.json +75e0c8fea601eecd505e00084e3001d54b315484 assets/create/lang/en_us.json +3f1b5016f59fc581352c4acca569dd68e82d96de assets/create/lang/unfinished/de_de.json 77c60af805305234d28421be451a6091c9222d44 assets/create/lang/unfinished/es_es.json -d623da600d9f84f7ace4689b44e982746364cd36 assets/create/lang/unfinished/es_mx.json +00cdb52c58844b3d9b00551929866ff7eb23aff8 assets/create/lang/unfinished/es_mx.json 41b68809a2c0267be7e6966274e00a69f370b743 assets/create/lang/unfinished/fr_fr.json 4606b3e7bcbb0b54802e52a800838343e84087ee assets/create/lang/unfinished/it_it.json 38e23ba73a515cb238d3899cc7517ff30223a3bc assets/create/lang/unfinished/ja_jp.json 0e34e4848b8e0ea0b73778477cc4790d6a637143 assets/create/lang/unfinished/ko_kr.json -3d790d06451adfab91ed133e80239df6e6221567 assets/create/lang/unfinished/nl_nl.json -d2e1804d40933c6b6e3badcc1ae197f80fb839af assets/create/lang/unfinished/pt_br.json +f8c6e3946025b6af0172319b0a4fc12b6f12a10f assets/create/lang/unfinished/nl_nl.json +5a0d6736f89c5d9e78d893d8c6ceb4ee07b9428b assets/create/lang/unfinished/pt_br.json ae45aacb4418411dec1e6248637094efec94bd24 assets/create/lang/unfinished/ru_ru.json ba653601c0452116fd5f8b820a136b4833dcb426 assets/create/lang/unfinished/zh_cn.json 1087875125ce70b1543df07e3957b14b5ef60e9f assets/create/lang/unfinished/zh_tw.json diff --git a/src/generated/resources/assets/create/blockstates/fluid_pipe.json b/src/generated/resources/assets/create/blockstates/fluid_pipe.json index a4cffcde7..80a25280c 100644 --- a/src/generated/resources/assets/create/blockstates/fluid_pipe.json +++ b/src/generated/resources/assets/create/blockstates/fluid_pipe.json @@ -61,9 +61,9 @@ { "when": { "down": "false", - "north": "true", "up": "true", - "south": "false" + "south": "false", + "north": "true" }, "apply": { "model": "create:block/fluid_pipe/lu_x" @@ -72,9 +72,9 @@ { "when": { "down": "false", - "north": "false", "up": "true", - "south": "true" + "south": "true", + "north": "false" }, "apply": { "model": "create:block/fluid_pipe/ru_x" @@ -83,9 +83,9 @@ { "when": { "down": "true", - "north": "true", "up": "false", - "south": "false" + "south": "false", + "north": "true" }, "apply": { "model": "create:block/fluid_pipe/ld_x" @@ -94,9 +94,9 @@ { "when": { "down": "true", - "north": "false", "up": "false", - "south": "true" + "south": "true", + "north": "false" }, "apply": { "model": "create:block/fluid_pipe/rd_x" @@ -105,9 +105,9 @@ { "when": { "down": "true", - "north": "false", "up": "true", - "south": "false" + "south": "false", + "north": "false" }, "apply": { "model": "create:block/fluid_pipe/ud_x" @@ -116,9 +116,9 @@ { "when": { "down": "false", - "north": "false", "up": "true", - "south": "false" + "south": "false", + "north": "false" }, "apply": { "model": "create:block/fluid_pipe/ud_x" @@ -127,9 +127,9 @@ { "when": { "down": "true", - "north": "false", "up": "false", - "south": "false" + "south": "false", + "north": "false" }, "apply": { "model": "create:block/fluid_pipe/ud_x" @@ -138,9 +138,9 @@ { "when": { "down": "false", - "north": "true", "up": "false", - "south": "true" + "south": "true", + "north": "true" }, "apply": { "model": "create:block/fluid_pipe/lr_x" @@ -149,9 +149,9 @@ { "when": { "down": "false", - "north": "true", "up": "false", - "south": "false" + "south": "false", + "north": "true" }, "apply": { "model": "create:block/fluid_pipe/lr_x" @@ -160,9 +160,9 @@ { "when": { "down": "false", - "north": "false", "up": "false", - "south": "true" + "south": "true", + "north": "false" }, "apply": { "model": "create:block/fluid_pipe/lr_x" @@ -171,9 +171,9 @@ { "when": { "down": "false", - "north": "false", "up": "false", - "south": "false" + "south": "false", + "north": "false" }, "apply": { "model": "create:block/fluid_pipe/none_x" @@ -181,10 +181,10 @@ }, { "when": { + "south": "true", "west": "true", - "east": "false", "north": "false", - "south": "true" + "east": "false" }, "apply": { "model": "create:block/fluid_pipe/lu_y" @@ -192,10 +192,10 @@ }, { "when": { + "south": "true", "west": "false", - "east": "true", "north": "false", - "south": "true" + "east": "true" }, "apply": { "model": "create:block/fluid_pipe/ru_y" @@ -203,10 +203,10 @@ }, { "when": { + "south": "false", "west": "true", - "east": "false", "north": "true", - "south": "false" + "east": "false" }, "apply": { "model": "create:block/fluid_pipe/ld_y" @@ -214,10 +214,10 @@ }, { "when": { + "south": "false", "west": "false", - "east": "true", "north": "true", - "south": "false" + "east": "true" }, "apply": { "model": "create:block/fluid_pipe/rd_y" @@ -225,10 +225,10 @@ }, { "when": { + "south": "true", "west": "false", - "east": "false", "north": "true", - "south": "true" + "east": "false" }, "apply": { "model": "create:block/fluid_pipe/ud_y" @@ -236,10 +236,10 @@ }, { "when": { + "south": "true", "west": "false", - "east": "false", "north": "false", - "south": "true" + "east": "false" }, "apply": { "model": "create:block/fluid_pipe/ud_y" @@ -247,10 +247,10 @@ }, { "when": { + "south": "false", "west": "false", - "east": "false", "north": "true", - "south": "false" + "east": "false" }, "apply": { "model": "create:block/fluid_pipe/ud_y" @@ -258,10 +258,10 @@ }, { "when": { + "south": "false", "west": "true", - "east": "true", "north": "false", - "south": "false" + "east": "true" }, "apply": { "model": "create:block/fluid_pipe/lr_y" @@ -269,10 +269,10 @@ }, { "when": { + "south": "false", "west": "true", - "east": "false", "north": "false", - "south": "false" + "east": "false" }, "apply": { "model": "create:block/fluid_pipe/lr_y" @@ -280,10 +280,10 @@ }, { "when": { + "south": "false", "west": "false", - "east": "true", "north": "false", - "south": "false" + "east": "true" }, "apply": { "model": "create:block/fluid_pipe/lr_y" @@ -291,10 +291,10 @@ }, { "when": { + "south": "false", "west": "false", - "east": "false", "north": "false", - "south": "false" + "east": "false" }, "apply": { "model": "create:block/fluid_pipe/none_y" @@ -302,10 +302,10 @@ }, { "when": { - "west": "false", "down": "false", - "east": "true", - "up": "true" + "up": "true", + "west": "false", + "east": "true" }, "apply": { "model": "create:block/fluid_pipe/lu_z" @@ -313,10 +313,10 @@ }, { "when": { - "west": "true", "down": "false", - "east": "false", - "up": "true" + "up": "true", + "west": "true", + "east": "false" }, "apply": { "model": "create:block/fluid_pipe/ru_z" @@ -324,10 +324,10 @@ }, { "when": { - "west": "false", "down": "true", - "east": "true", - "up": "false" + "up": "false", + "west": "false", + "east": "true" }, "apply": { "model": "create:block/fluid_pipe/ld_z" @@ -335,10 +335,10 @@ }, { "when": { - "west": "true", "down": "true", - "east": "false", - "up": "false" + "up": "false", + "west": "true", + "east": "false" }, "apply": { "model": "create:block/fluid_pipe/rd_z" @@ -346,10 +346,10 @@ }, { "when": { - "west": "false", "down": "true", - "east": "false", - "up": "true" + "up": "true", + "west": "false", + "east": "false" }, "apply": { "model": "create:block/fluid_pipe/ud_z" @@ -357,10 +357,10 @@ }, { "when": { - "west": "false", "down": "false", - "east": "false", - "up": "true" + "up": "true", + "west": "false", + "east": "false" }, "apply": { "model": "create:block/fluid_pipe/ud_z" @@ -368,10 +368,10 @@ }, { "when": { - "west": "false", "down": "true", - "east": "false", - "up": "false" + "up": "false", + "west": "false", + "east": "false" }, "apply": { "model": "create:block/fluid_pipe/ud_z" @@ -379,10 +379,10 @@ }, { "when": { + "down": "false", + "up": "false", "west": "true", - "down": "false", - "east": "true", - "up": "false" + "east": "true" }, "apply": { "model": "create:block/fluid_pipe/lr_z" @@ -390,10 +390,10 @@ }, { "when": { + "down": "false", + "up": "false", "west": "false", - "down": "false", - "east": "true", - "up": "false" + "east": "true" }, "apply": { "model": "create:block/fluid_pipe/lr_z" @@ -401,10 +401,10 @@ }, { "when": { + "down": "false", + "up": "false", "west": "true", - "down": "false", - "east": "false", - "up": "false" + "east": "false" }, "apply": { "model": "create:block/fluid_pipe/lr_z" @@ -412,10 +412,10 @@ }, { "when": { - "west": "false", "down": "false", - "east": "false", - "up": "false" + "up": "false", + "west": "false", + "east": "false" }, "apply": { "model": "create:block/fluid_pipe/none_z" diff --git a/src/generated/resources/assets/create/blockstates/radial_chassis.json b/src/generated/resources/assets/create/blockstates/radial_chassis.json index 9d00ea8b1..f97d8c8bc 100644 --- a/src/generated/resources/assets/create/blockstates/radial_chassis.json +++ b/src/generated/resources/assets/create/blockstates/radial_chassis.json @@ -29,8 +29,8 @@ }, { "when": { - "sticky_south": "true", - "axis": "x" + "axis": "x", + "sticky_south": "true" }, "apply": { "model": "create:block/radial_chassis_side_x_sticky", @@ -39,8 +39,8 @@ }, { "when": { - "sticky_south": "true", - "axis": "y" + "axis": "y", + "sticky_south": "true" }, "apply": { "model": "create:block/radial_chassis_side_y_sticky" @@ -48,8 +48,8 @@ }, { "when": { - "sticky_south": "true", - "axis": "z" + "axis": "z", + "sticky_south": "true" }, "apply": { "model": "create:block/radial_chassis_side_x_sticky", @@ -59,8 +59,8 @@ }, { "when": { - "sticky_south": "false", - "axis": "x" + "axis": "x", + "sticky_south": "false" }, "apply": { "model": "create:block/radial_chassis_side_x", @@ -69,8 +69,8 @@ }, { "when": { - "sticky_south": "false", - "axis": "y" + "axis": "y", + "sticky_south": "false" }, "apply": { "model": "create:block/radial_chassis_side_y" @@ -78,8 +78,8 @@ }, { "when": { - "sticky_south": "false", - "axis": "z" + "axis": "z", + "sticky_south": "false" }, "apply": { "model": "create:block/radial_chassis_side_x", diff --git a/src/generated/resources/assets/create/lang/en_us.json b/src/generated/resources/assets/create/lang/en_us.json index 690dd2fbe..a3054d2c0 100644 --- a/src/generated/resources/assets/create/lang/en_us.json +++ b/src/generated/resources/assets/create/lang/en_us.json @@ -878,7 +878,7 @@ "create.schematicAndQuill.noTarget": "Hold [Ctrl] to select Air blocks.", "create.schematicAndQuill.abort": "Removed selection.", "create.schematicAndQuill.title": "Schematic Name:", - "create.schematicAndQuill.convert": "Save and Deploy Immediately", + "create.schematicAndQuill.convert": "Save and Upload Immediately", "create.schematicAndQuill.fallbackName": "My Schematic", "create.schematicAndQuill.saved": "Saved as %1$s", @@ -893,12 +893,12 @@ "create.schematic.mirror.none": "None", "create.schematic.mirror.frontBack": "Front-Back", "create.schematic.mirror.leftRight": "Left-Right", - "create.schematic.tool.deploy": "Deploy", + "create.schematic.tool.deploy": "Position", "create.schematic.tool.move": "Move XZ", "create.schematic.tool.movey": "Move Y", "create.schematic.tool.rotate": "Rotate", "create.schematic.tool.print": "Print", - "create.schematic.tool.flip": "Flip", + "create.schematic.tool.flip": "Mirror", "create.schematic.tool.deploy.description.0": "Moves the structure to a location.", "create.schematic.tool.deploy.description.1": "Right-Click on the ground to place.", "create.schematic.tool.deploy.description.2": "Hold [Ctrl] to select at a fixed distance.", @@ -974,7 +974,7 @@ "create.schematicannon.status.placing": "Placing", "create.schematicannon.status.clearing": "Clearing Blocks", "create.schematicannon.status.schematicInvalid": "Schematic Invalid", - "create.schematicannon.status.schematicNotPlaced": "Schematic Not Deployed", + "create.schematicannon.status.schematicNotPlaced": "Schematic not Positioned", "create.schematicannon.status.schematicExpired": "Schematic File Expired", "create.materialChecklist": "Material Checklist", diff --git a/src/generated/resources/assets/create/lang/unfinished/de_de.json b/src/generated/resources/assets/create/lang/unfinished/de_de.json index 8e489b370..8403ebbb3 100644 --- a/src/generated/resources/assets/create/lang/unfinished/de_de.json +++ b/src/generated/resources/assets/create/lang/unfinished/de_de.json @@ -879,7 +879,7 @@ "create.schematicAndQuill.noTarget": "Halte [Strg] zur Auswahl von Luft.", "create.schematicAndQuill.abort": "Auswahl zurückgesetzt.", "create.schematicAndQuill.title": "Bauplanname:", - "create.schematicAndQuill.convert": "UNLOCALIZED: Save and Deploy Immediately", + "create.schematicAndQuill.convert": "UNLOCALIZED: Save and Upload Immediately", "create.schematicAndQuill.fallbackName": "Mein Bauplan", "create.schematicAndQuill.saved": "Gespeichert als %1$s", diff --git a/src/generated/resources/assets/create/lang/unfinished/es_mx.json b/src/generated/resources/assets/create/lang/unfinished/es_mx.json index 854c8e156..e0c794f9e 100644 --- a/src/generated/resources/assets/create/lang/unfinished/es_mx.json +++ b/src/generated/resources/assets/create/lang/unfinished/es_mx.json @@ -879,7 +879,7 @@ "create.schematicAndQuill.noTarget": "UNLOCALIZED: Hold [Ctrl] to select Air blocks.", "create.schematicAndQuill.abort": "UNLOCALIZED: Removed selection.", "create.schematicAndQuill.title": "UNLOCALIZED: Schematic Name:", - "create.schematicAndQuill.convert": "UNLOCALIZED: Save and Deploy Immediately", + "create.schematicAndQuill.convert": "UNLOCALIZED: Save and Upload Immediately", "create.schematicAndQuill.fallbackName": "UNLOCALIZED: My Schematic", "create.schematicAndQuill.saved": "UNLOCALIZED: Saved as %1$s", @@ -894,12 +894,12 @@ "create.schematic.mirror.none": "UNLOCALIZED: None", "create.schematic.mirror.frontBack": "UNLOCALIZED: Front-Back", "create.schematic.mirror.leftRight": "UNLOCALIZED: Left-Right", - "create.schematic.tool.deploy": "UNLOCALIZED: Deploy", + "create.schematic.tool.deploy": "UNLOCALIZED: Position", "create.schematic.tool.move": "UNLOCALIZED: Move XZ", "create.schematic.tool.movey": "UNLOCALIZED: Move Y", "create.schematic.tool.rotate": "UNLOCALIZED: Rotate", "create.schematic.tool.print": "UNLOCALIZED: Print", - "create.schematic.tool.flip": "UNLOCALIZED: Flip", + "create.schematic.tool.flip": "UNLOCALIZED: Mirror", "create.schematic.tool.deploy.description.0": "UNLOCALIZED: Moves the structure to a location.", "create.schematic.tool.deploy.description.1": "UNLOCALIZED: Right-Click on the ground to place.", "create.schematic.tool.deploy.description.2": "UNLOCALIZED: Hold [Ctrl] to select at a fixed distance.", @@ -975,7 +975,7 @@ "create.schematicannon.status.placing": "UNLOCALIZED: Placing", "create.schematicannon.status.clearing": "UNLOCALIZED: Clearing Blocks", "create.schematicannon.status.schematicInvalid": "UNLOCALIZED: Schematic Invalid", - "create.schematicannon.status.schematicNotPlaced": "UNLOCALIZED: Schematic Not Deployed", + "create.schematicannon.status.schematicNotPlaced": "UNLOCALIZED: Schematic not Positioned", "create.schematicannon.status.schematicExpired": "UNLOCALIZED: Schematic File Expired", "create.materialChecklist": "UNLOCALIZED: Material Checklist", diff --git a/src/generated/resources/assets/create/lang/unfinished/nl_nl.json b/src/generated/resources/assets/create/lang/unfinished/nl_nl.json index 8c7090e72..1d6f597aa 100644 --- a/src/generated/resources/assets/create/lang/unfinished/nl_nl.json +++ b/src/generated/resources/assets/create/lang/unfinished/nl_nl.json @@ -879,7 +879,7 @@ "create.schematicAndQuill.noTarget": "Houd [Ctrl] ingedrukt om een Lucht block te kiezen.", "create.schematicAndQuill.abort": "Keuze verwijderd.", "create.schematicAndQuill.title": "UNLOCALIZED: Schematic Name:", - "create.schematicAndQuill.convert": "UNLOCALIZED: Save and Deploy Immediately", + "create.schematicAndQuill.convert": "UNLOCALIZED: Save and Upload Immediately", "create.schematicAndQuill.fallbackName": "Mijn Bouwtekening", "create.schematicAndQuill.saved": "Opgeslagen als %1$s", diff --git a/src/generated/resources/assets/create/lang/unfinished/pt_br.json b/src/generated/resources/assets/create/lang/unfinished/pt_br.json index 69c3540e9..7d318a947 100644 --- a/src/generated/resources/assets/create/lang/unfinished/pt_br.json +++ b/src/generated/resources/assets/create/lang/unfinished/pt_br.json @@ -879,7 +879,7 @@ "create.schematicAndQuill.noTarget": "Seguro [Ctrl] para selecionar Blocos de Ar.", "create.schematicAndQuill.abort": "Seleção removida.", "create.schematicAndQuill.title": "UNLOCALIZED: Schematic Name:", - "create.schematicAndQuill.convert": "UNLOCALIZED: Save and Deploy Immediately", + "create.schematicAndQuill.convert": "UNLOCALIZED: Save and Upload Immediately", "create.schematicAndQuill.fallbackName": "Meu Esquema", "create.schematicAndQuill.saved": "Salvo como %1$s", diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java index 83738f6dd..d1825eef9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java @@ -3,31 +3,48 @@ package com.simibubi.create.content.contraptions.components.deployer; import java.util.Arrays; import java.util.List; -import com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance; -import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionKineticRenderer; -import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; +import javax.annotation.Nullable; + import org.apache.commons.lang3.tuple.Pair; import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.AllBlocks; +import com.simibubi.create.AllItems; +import com.simibubi.create.AllTags.AllBlockTags; import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.Mode; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionKineticRenderer; import com.simibubi.create.content.logistics.item.filter.FilterItem; +import com.simibubi.create.content.schematics.ItemRequirement; +import com.simibubi.create.content.schematics.SchematicWorld; +import com.simibubi.create.content.schematics.filtering.SchematicInstances; import com.simibubi.create.foundation.item.ItemHelper; +import com.simibubi.create.foundation.item.ItemHelper.ExtractionCountMode; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; +import com.simibubi.create.foundation.utility.BlockHelper; import com.simibubi.create.foundation.utility.NBTHelper; +import com.simibubi.create.foundation.utility.NBTProcessors; +import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.ListNBT; +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.Vec3d; +import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; +import net.minecraftforge.common.util.BlockSnapshot; import net.minecraftforge.common.util.Constants.NBT; - -import javax.annotation.Nullable; +import net.minecraftforge.event.ForgeEventFactory; +import net.minecraftforge.items.IItemHandler; public class DeployerMovementBehaviour extends MovementBehaviour { @@ -54,6 +71,12 @@ public class DeployerMovementBehaviour extends MovementBehaviour { } public void activate(MovementContext context, BlockPos pos, DeployerFakePlayer player, Mode mode) { + World world = context.world; + + ItemStack filter = getFilter(context); + if (AllItems.SCHEMATIC.isIn(filter)) + activateAsSchematicPrinter(context, pos, player, world, filter); + Vec3d facingVec = new Vec3d(context.state.get(DeployerBlock.FACING) .getDirectionVec()); facingVec = context.rotation.apply(facingVec); @@ -64,6 +87,61 @@ public class DeployerMovementBehaviour extends MovementBehaviour { DeployerHandler.activate(player, vec, pos, facingVec, mode); } + protected void activateAsSchematicPrinter(MovementContext context, BlockPos pos, DeployerFakePlayer player, World world, + ItemStack filter) { + if (!filter.hasTag()) + return; + if (!world.getBlockState(pos) + .getMaterial() + .isReplaceable()) + return; + + CompoundNBT tag = filter.getTag(); + if (!tag.getBoolean("Deployed")) + return; + SchematicWorld schematicWorld = SchematicInstances.get(world, filter); + if (!schematicWorld.getBounds() + .isVecInside(pos.subtract(schematicWorld.anchor))) + return; + BlockState blockState = schematicWorld.getBlockState(pos); + ItemRequirement requirement = ItemRequirement.of(blockState); + if (requirement.isInvalid() || requirement.isEmpty()) + return; + if (AllBlocks.BELT.has(blockState)) + return; + + List requiredItems = requirement.getRequiredItems(); + ItemStack firstRequired = requiredItems.isEmpty() ? ItemStack.EMPTY : requiredItems.get(0); + IItemHandler iItemHandler = context.contraption.inventory; + + for (ItemStack required : requiredItems) { + int amountFound = ItemHelper + .extract(iItemHandler, s -> ItemRequirement.validate(required, s), ExtractionCountMode.UPTO, + required.getCount(), true) + .getCount(); + if (amountFound < required.getCount()) + return; + } + + for (ItemStack required : requiredItems) + ItemHelper.extract(iItemHandler, s -> ItemRequirement.validate(required, s), ExtractionCountMode.UPTO, + required.getCount(), false); + + CompoundNBT data = null; + if (AllBlockTags.SAFE_NBT.matches(blockState)) { + TileEntity tile = world.getTileEntity(pos); + if (tile != null) { + data = tile.write(new CompoundNBT()); + data = NBTProcessors.process(tile, data, true); + } + } + + BlockSnapshot blocksnapshot = BlockSnapshot.getBlockSnapshot(world, pos); + BlockHelper.placeSchematicBlock(world, blockState, pos, firstRequired, data); + if (ForgeEventFactory.onBlockPlace(player, blocksnapshot, Direction.UP)) + blocksnapshot.restore(true, false); + } + @Override public void tick(MovementContext context) { if (context.world.isRemote) @@ -111,6 +189,8 @@ public class DeployerMovementBehaviour extends MovementBehaviour { if (player.getHeldItemMainhand() .isEmpty()) { ItemStack filter = getFilter(context); + if (AllItems.SCHEMATIC.isIn(filter)) + return; ItemStack held = ItemHelper.extract(context.contraption.inventory, stack -> FilterItem.test(context.world, stack, filter), 1, false); player.setHeldItem(Hand.MAIN_HAND, held); diff --git a/src/main/java/com/simibubi/create/content/schematics/block/LaunchedItem.java b/src/main/java/com/simibubi/create/content/schematics/block/LaunchedItem.java index f2127a1cb..1e123ebfb 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/LaunchedItem.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/LaunchedItem.java @@ -3,31 +3,22 @@ package com.simibubi.create.content.schematics.block; import java.util.Optional; import com.simibubi.create.AllBlocks; -import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.relays.belt.BeltBlock; import com.simibubi.create.content.contraptions.relays.belt.BeltPart; import com.simibubi.create.content.contraptions.relays.belt.item.BeltConnectorItem; import com.simibubi.create.content.contraptions.relays.elementary.AbstractShaftBlock; +import com.simibubi.create.foundation.utility.BlockHelper; -import net.minecraft.block.Block; import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.NBTUtil; -import net.minecraft.particles.ParticleTypes; -import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tags.FluidTags; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction.Axis; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvents; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; -import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.util.Constants; public abstract class LaunchedItem { @@ -128,46 +119,7 @@ public abstract class LaunchedItem { @Override void place(World world) { - // Piston - if (state.has(BlockStateProperties.EXTENDED)) - state = state.with(BlockStateProperties.EXTENDED, Boolean.FALSE); - if (state.has(BlockStateProperties.WATERLOGGED)) - state = state.with(BlockStateProperties.WATERLOGGED, Boolean.FALSE); - - if (AllBlocks.BELT.has(state)) { - world.setBlockState(target, state, 2); - return; - } - else if (state.getBlock() == Blocks.COMPOSTER) - state = Blocks.COMPOSTER.getDefaultState(); - else if (state.getBlock() != Blocks.SEA_PICKLE && state.getBlock() instanceof IPlantable) - state = ((IPlantable) state.getBlock()).getPlant(world, target); - - if (world.dimension.doesWaterVaporize() && state.getFluidState().getFluid().isIn(FluidTags.WATER)) { - int i = target.getX(); - int j = target.getY(); - int k = target.getZ(); - world.playSound(null, target, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F); - - for (int l = 0; l < 8; ++l) { - world.addParticle(ParticleTypes.LARGE_SMOKE, i + Math.random(), j + Math.random(), k + Math.random(), 0.0D, 0.0D, 0.0D); - } - Block.spawnDrops(state, world, target); - return; - } - world.setBlockState(target, state, 18); - if (data != null) { - TileEntity tile = world.getTileEntity(target); - if (tile != null) { - data.putInt("x", target.getX()); - data.putInt("y", target.getY()); - data.putInt("z", target.getZ()); - if (tile instanceof KineticTileEntity) - ((KineticTileEntity) tile).warnOfMovement(); - tile.read(data); - } - } - state.getBlock().onBlockPlacedBy(world, target, state, null, stack); + BlockHelper.placeSchematicBlock(world, state, target, stack, data); } } diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonTileEntity.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonTileEntity.java index e3317d9aa..156c434fd 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonTileEntity.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonTileEntity.java @@ -176,7 +176,7 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC if (compound.contains("CurrentPos")) currentPos = NBTUtil.readBlockPos(compound.getCompound("CurrentPos")); } - + // Gui information statusMsg = compound.getString("Status"); schematicProgress = compound.getFloat("Progress"); @@ -186,17 +186,17 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC blocksPlaced = compound.getInt("AmountPlaced"); blocksToPlace = compound.getInt("AmountToPlace"); printingEntityIndex = compound.getInt("EntityProgress"); - + missingItem = null; if (compound.contains("MissingItem")) missingItem = ItemStack.read(compound.getCompound("MissingItem")); - + // Settings CompoundNBT options = compound.getCompound("Options"); replaceMode = options.getInt("ReplaceMode"); skipMissing = options.getBoolean("SkipMissing"); replaceTileEntities = options.getBoolean("ReplaceTileEntities"); - + // Printer & Flying Blocks if (compound.contains("Target")) target = NBTUtil.readBlockPos(compound.getCompound("Target")); @@ -251,7 +251,7 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC compound.put("CurrentPos", NBTUtil.writeBlockPos(currentPos)); } } - + // Gui information compound.putFloat("Progress", schematicProgress); compound.putFloat("PaperProgress", bookPrintingProgress); @@ -261,17 +261,17 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC compound.putInt("AmountPlaced", blocksPlaced); compound.putInt("AmountToPlace", blocksToPlace); compound.putInt("EntityProgress", printingEntityIndex); - + if (missingItem != null) compound.put("MissingItem", missingItem.serializeNBT()); - + // Settings CompoundNBT options = new CompoundNBT(); options.putInt("ReplaceMode", replaceMode); options.putBoolean("SkipMissing", skipMissing); options.putBoolean("ReplaceTileEntities", replaceTileEntities); compound.put("Options", options); - + // Printer & Flying Blocks if (target != null) compound.put("Target", NBTUtil.writeBlockPos(target)); @@ -376,11 +376,13 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC } if (missingItem == null && !positionNotLoaded) { - advanceCurrentPos(); + do { + advanceCurrentPos(); + if (state == State.STOPPED) + return; - // End reached - if (state == State.STOPPED) - return; + } while (!blockReader.getBounds() + .isVecInside(currentPos)); sendUpdate = true; target = schematicAnchor.add(currentPos); @@ -711,10 +713,12 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC if (world == null) return false; BlockState toReplace = world.getBlockState(pos); - boolean placingAir = state.getBlock().isAir(state, world, pos); + boolean placingAir = state.getBlock() + .isAir(state, world, pos); BlockState toReplaceOther = null; - if (state.has(BlockStateProperties.BED_PART) && state.has(BlockStateProperties.HORIZONTAL_FACING) && state.get(BlockStateProperties.BED_PART) == BedPart.FOOT) + if (state.has(BlockStateProperties.BED_PART) && state.has(BlockStateProperties.HORIZONTAL_FACING) + && state.get(BlockStateProperties.BED_PART) == BedPart.FOOT) toReplaceOther = world.getBlockState(pos.offset(state.get(BlockStateProperties.HORIZONTAL_FACING))); if (state.has(BlockStateProperties.DOUBLE_BLOCK_HALF) && state.get(BlockStateProperties.DOUBLE_BLOCK_HALF) == DoubleBlockHalf.LOWER) @@ -727,11 +731,13 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC return false; if (toReplace == state) return false; - if (toReplace.getBlockHardness(world, pos) == -1 || (toReplaceOther != null && toReplaceOther.getBlockHardness(world, pos) == -1)) + if (toReplace.getBlockHardness(world, pos) == -1 + || (toReplaceOther != null && toReplaceOther.getBlockHardness(world, pos) == -1)) return false; if (pos.withinDistance(getPos(), 2f)) return false; - if (!replaceTileEntities && (toReplace.hasTileEntity() || (toReplaceOther != null && toReplaceOther.hasTileEntity()))) + if (!replaceTileEntities + && (toReplace.hasTileEntity() || (toReplaceOther != null && toReplaceOther.hasTileEntity()))) return false; if (shouldIgnoreBlockState(state)) @@ -742,10 +748,12 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC if (replaceMode == 2 && !placingAir) return true; if (replaceMode == 1 - && (state.isNormalCube(blockReader, pos.subtract(schematicAnchor)) || (!toReplace.isNormalCube(world, pos) && (toReplaceOther == null || !toReplaceOther.isNormalCube(world, pos)))) + && (state.isNormalCube(blockReader, pos.subtract(schematicAnchor)) || (!toReplace.isNormalCube(world, pos) + && (toReplaceOther == null || !toReplaceOther.isNormalCube(world, pos)))) && !placingAir) return true; - if (replaceMode == 0 && !toReplace.isNormalCube(world, pos) && (toReplaceOther == null || !toReplaceOther.isNormalCube(world, pos)) && !placingAir) + if (replaceMode == 0 && !toReplace.isNormalCube(world, pos) + && (toReplaceOther == null || !toReplaceOther.isNormalCube(world, pos)) && !placingAir) return true; return false; @@ -755,7 +763,7 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC // Block doesnt have a mapping (Water, lava, etc) if (state.getBlock() == Blocks.STRUCTURE_VOID) return true; - + ItemRequirement requirement = ItemRequirement.of(state); if (requirement.isEmpty()) return false; @@ -852,7 +860,8 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC } protected void launchBlock(BlockPos target, ItemStack stack, BlockState state, @Nullable CompoundNBT data) { - if (state.getBlock().isAir(state, world, target)) + if (state.getBlock() + .isAir(state, world, target)) blocksPlaced++; flyingBlocks.add(new LaunchedItem.ForBlockState(this.getPos(), target, stack, state, data)); playFiringSound(); diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java index 74c6b9eac..8d30e6f8f 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java @@ -20,6 +20,7 @@ import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.outliner.AABBOutline; +import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -206,7 +207,10 @@ public class SchematicHandler { return; if (mc.objectMouseOver instanceof BlockRayTraceResult) { BlockRayTraceResult blockRayTraceResult = (BlockRayTraceResult) mc.objectMouseOver; - if (AllBlocks.SCHEMATICANNON.has(mc.world.getBlockState(blockRayTraceResult.getPos()))) + BlockState clickedBlock = mc.world.getBlockState(blockRayTraceResult.getPos()); + if (AllBlocks.SCHEMATICANNON.has(clickedBlock)) + return; + if (AllBlocks.DEPLOYER.has(clickedBlock)) return; } currentTool.getTool() diff --git a/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java b/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java index e516b3c6d..bd2045f84 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java @@ -2,10 +2,16 @@ package com.simibubi.create.foundation.utility; import java.util.function.Consumer; +import javax.annotation.Nullable; + import org.apache.commons.lang3.mutable.MutableInt; +import com.simibubi.create.AllBlocks; +import com.simibubi.create.content.contraptions.base.KineticTileEntity; + import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; import net.minecraft.client.particle.DiggingParticle; import net.minecraft.client.particle.ParticleManager; import net.minecraft.entity.player.PlayerEntity; @@ -13,10 +19,15 @@ import net.minecraft.fluid.IFluidState; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.particles.ParticleTypes; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.SlabType; +import net.minecraft.tags.FluidTags; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvents; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.shapes.VoxelShape; @@ -26,6 +37,7 @@ import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.common.IPlantable; public class BlockHelper { @@ -164,7 +176,7 @@ public class BlockHelper { public static void destroyBlock(World world, BlockPos pos, float effectChance, Consumer droppedItemCallback) { - + IFluidState ifluidstate = world.getFluidState(pos); BlockState state = world.getBlockState(pos); if (world.rand.nextFloat() < effectChance) @@ -185,9 +197,63 @@ public class BlockHelper { return Block.hasSolidSide(reader.getBlockState(fromPos.offset(toDirection)), reader, fromPos.offset(toDirection), toDirection.getOpposite()); } - + public static boolean noCollisionInSpace(IBlockReader reader, BlockPos pos) { - return reader.getBlockState(pos).getCollisionShape(reader, pos).isEmpty(); + return reader.getBlockState(pos) + .getCollisionShape(reader, pos) + .isEmpty(); + } + + public static void placeSchematicBlock(World world, BlockState state, BlockPos target, ItemStack stack, + @Nullable CompoundNBT data) { + // Piston + if (state.has(BlockStateProperties.EXTENDED)) + state = state.with(BlockStateProperties.EXTENDED, Boolean.FALSE); + if (state.has(BlockStateProperties.WATERLOGGED)) + state = state.with(BlockStateProperties.WATERLOGGED, Boolean.FALSE); + + if (AllBlocks.BELT.has(state)) { + world.setBlockState(target, state, 2); + return; + } else if (state.getBlock() == Blocks.COMPOSTER) + state = Blocks.COMPOSTER.getDefaultState(); + else if (state.getBlock() != Blocks.SEA_PICKLE && state.getBlock() instanceof IPlantable) + state = ((IPlantable) state.getBlock()).getPlant(world, target); + + if (world.dimension.doesWaterVaporize() && state.getFluidState() + .getFluid() + .isIn(FluidTags.WATER)) { + int i = target.getX(); + int j = target.getY(); + int k = target.getZ(); + world.playSound(null, target, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, + 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F); + + for (int l = 0; l < 8; ++l) { + world.addParticle(ParticleTypes.LARGE_SMOKE, i + Math.random(), j + Math.random(), k + Math.random(), + 0.0D, 0.0D, 0.0D); + } + Block.spawnDrops(state, world, target); + return; + } + world.setBlockState(target, state, 18); + if (data != null) { + TileEntity tile = world.getTileEntity(target); + if (tile != null) { + data.putInt("x", target.getX()); + data.putInt("y", target.getY()); + data.putInt("z", target.getZ()); + if (tile instanceof KineticTileEntity) + ((KineticTileEntity) tile).warnOfMovement(); + tile.read(data); + } + } + + try { + state.getBlock() + .onBlockPlacedBy(world, target, state, null, stack); + } catch (Exception e) { + } } } diff --git a/src/main/resources/assets/create/lang/default/messages.json b/src/main/resources/assets/create/lang/default/messages.json index a5176a70f..f2212a3c6 100644 --- a/src/main/resources/assets/create/lang/default/messages.json +++ b/src/main/resources/assets/create/lang/default/messages.json @@ -228,7 +228,7 @@ "create.schematicAndQuill.noTarget": "Hold [Ctrl] to select Air blocks.", "create.schematicAndQuill.abort": "Removed selection.", "create.schematicAndQuill.title": "Schematic Name:", - "create.schematicAndQuill.convert": "Save and Deploy Immediately", + "create.schematicAndQuill.convert": "Save and Upload Immediately", "create.schematicAndQuill.fallbackName": "My Schematic", "create.schematicAndQuill.saved": "Saved as %1$s", @@ -244,12 +244,12 @@ "create.schematic.mirror.frontBack": "Front-Back", "create.schematic.mirror.leftRight": "Left-Right", - "create.schematic.tool.deploy": "Deploy", + "create.schematic.tool.deploy": "Position", "create.schematic.tool.move": "Move XZ", "create.schematic.tool.movey": "Move Y", "create.schematic.tool.rotate": "Rotate", "create.schematic.tool.print": "Print", - "create.schematic.tool.flip": "Flip", + "create.schematic.tool.flip": "Mirror", "create.schematic.tool.deploy.description.0": "Moves the structure to a location.", "create.schematic.tool.deploy.description.1": "Right-Click on the ground to place.", @@ -329,7 +329,7 @@ "create.schematicannon.status.placing": "Placing", "create.schematicannon.status.clearing": "Clearing Blocks", "create.schematicannon.status.schematicInvalid": "Schematic Invalid", - "create.schematicannon.status.schematicNotPlaced": "Schematic Not Deployed", + "create.schematicannon.status.schematicNotPlaced": "Schematic not Positioned", "create.schematicannon.status.schematicExpired": "Schematic File Expired", "create.materialChecklist": "Material Checklist", From 60bc6102e246ceecb948fd5033605cbb783696e6 Mon Sep 17 00:00:00 2001 From: grimmauld Date: Fri, 26 Mar 2021 23:21:44 +0100 Subject: [PATCH 3/4] Add Create stone to base_stone_overworld block tag (terraforged was complaining) --- src/generated/resources/.cache/cache | 1 + .../minecraft/tags/blocks/base_stone_overworld.json | 10 ++++++++++ src/main/java/com/simibubi/create/AllBlocks.java | 6 +++--- src/main/java/com/simibubi/create/AllTags.java | 3 +-- .../create/content/palettes/AllPaletteBlocks.java | 5 +++++ 5 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 src/generated/resources/data/minecraft/tags/blocks/base_stone_overworld.json diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index d0c689770..76c10722a 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -3696,6 +3696,7 @@ ff1900963bc4cd8ceffa78d58ef1952ceacb2fb7 data/forge/tags/items/storage_blocks/br f6c8f34ceb475546dba5cc6ff288863ea795d20b data/forge/tags/items/storage_blocks/copper.json 7f71a774800111e50b42de0e6159ed2d2a807d32 data/forge/tags/items/storage_blocks/zinc.json 1376cd1f92903a1c4e1422719b1aa102438a216e data/minecraft/advancements/createchromatic_age.json +2072c51afc5bbc6c9d64fd086803193d8a3c40de data/minecraft/tags/blocks/base_stone_overworld.json 508730d3822c54d355329bf6a33d58071653afad data/minecraft/tags/blocks/beacon_base_blocks.json 69f596fcb065e26b02ce246760432b5174191b76 data/minecraft/tags/blocks/impermeable.json 378b01e288301e0835d3d25167889077a2070780 data/minecraft/tags/blocks/rails.json diff --git a/src/generated/resources/data/minecraft/tags/blocks/base_stone_overworld.json b/src/generated/resources/data/minecraft/tags/blocks/base_stone_overworld.json new file mode 100644 index 000000000..39e5fd569 --- /dev/null +++ b/src/generated/resources/data/minecraft/tags/blocks/base_stone_overworld.json @@ -0,0 +1,10 @@ +{ + "replace": false, + "values": [ + "create:limestone", + "create:weathered_limestone", + "create:dolomite", + "create:gabbro", + "create:natural_scoria" + ] +} \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index 840de5a1f..a646636b0 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -1294,7 +1294,7 @@ public class AllBlocks { REGISTRATE.block("copper_block", p -> new OxidizingBlock(p, 1 / 32f)) .initialProperties(() -> Blocks.IRON_BLOCK) .tag(Tags.Blocks.STORAGE_BLOCKS) - .tag(AllBlockTags.BEACON_BASE_BLOCKS.tag) + .tag(BlockTags.BEACON_BASE_BLOCKS) .transform(tagBlockAndItem("storage_blocks/copper")) .tag(Tags.Items.STORAGE_BLOCKS) .transform(oxidizedItemModel()) @@ -1320,7 +1320,7 @@ public class AllBlocks { public static final BlockEntry ZINC_BLOCK = REGISTRATE.block("zinc_block", p -> new Block(p)) .initialProperties(() -> Blocks.IRON_BLOCK) .tag(Tags.Blocks.STORAGE_BLOCKS) - .tag(AllBlockTags.BEACON_BASE_BLOCKS.tag) + .tag(BlockTags.BEACON_BASE_BLOCKS) .transform(tagBlockAndItem("storage_blocks/zinc")) .tag(Tags.Items.STORAGE_BLOCKS) .build() @@ -1331,7 +1331,7 @@ public class AllBlocks { .blockstate((c, p) -> p.simpleBlock(c.get(), p.models() .cubeAll(c.getName(), p.modLoc("block/brass_storage_block")))) .tag(Tags.Blocks.STORAGE_BLOCKS) - .tag(AllBlockTags.BEACON_BASE_BLOCKS.tag) + .tag(BlockTags.BEACON_BASE_BLOCKS) .transform(tagBlockAndItem("storage_blocks/brass")) .tag(Tags.Items.STORAGE_BLOCKS) .build() diff --git a/src/main/java/com/simibubi/create/AllTags.java b/src/main/java/com/simibubi/create/AllTags.java index a017cc657..1a7768a7c 100644 --- a/src/main/java/com/simibubi/create/AllTags.java +++ b/src/main/java/com/simibubi/create/AllTags.java @@ -1,7 +1,6 @@ package com.simibubi.create; import static com.simibubi.create.AllTags.NameSpace.FORGE; -import static com.simibubi.create.AllTags.NameSpace.MC; import static com.simibubi.create.AllTags.NameSpace.MOD; import static com.simibubi.create.AllTags.NameSpace.TIC; @@ -142,7 +141,7 @@ public class AllTags { } public static enum AllBlockTags { - WINDMILL_SAILS, FAN_HEATERS, WINDOWABLE, NON_MOVABLE, BRITTLE, SEATS, SAILS, VALVE_HANDLES, FAN_TRANSPARENT, SAFE_NBT, SLIMY_LOGS(TIC), BEACON_BASE_BLOCKS(MC) + WINDMILL_SAILS, FAN_HEATERS, WINDOWABLE, NON_MOVABLE, BRITTLE, SEATS, SAILS, VALVE_HANDLES, FAN_TRANSPARENT, SAFE_NBT, SLIMY_LOGS(TIC) ; diff --git a/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java b/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java index f6f75708d..dfb730b13 100644 --- a/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java +++ b/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java @@ -114,6 +114,7 @@ public class AllPaletteBlocks { public static final BlockEntry LIMESTONE = REGISTRATE.baseBlock("limestone", Block::new, () -> Blocks.SANDSTONE, true) + .tag(BlockTags.BASE_STONE_OVERWORLD) .register(); public static final PalettesVariantEntry LIMESTONE_VARIANTS = @@ -121,6 +122,7 @@ public class AllPaletteBlocks { public static final BlockEntry WEATHERED_LIMESTONE = REGISTRATE.baseBlock("weathered_limestone", Block::new, () -> Blocks.SANDSTONE, true) + .tag(BlockTags.BASE_STONE_OVERWORLD) .register(); public static final PalettesVariantEntry WEATHERED_LIMESTONE_VARIANTS = new PalettesVariantEntry( @@ -128,6 +130,7 @@ public class AllPaletteBlocks { public static final BlockEntry DOLOMITE = REGISTRATE.baseBlock("dolomite", Block::new, () -> Blocks.QUARTZ_BLOCK, true) + .tag(BlockTags.BASE_STONE_OVERWORLD) .register(); public static final PalettesVariantEntry DOLOMITE_VARIANTS = @@ -135,6 +138,7 @@ public class AllPaletteBlocks { public static final BlockEntry GABBRO = REGISTRATE.baseBlock("gabbro", Block::new, () -> Blocks.ANDESITE, true) + .tag(BlockTags.BASE_STONE_OVERWORLD) .register(); public static final PalettesVariantEntry GABBRO_VARIANTS = @@ -146,6 +150,7 @@ public class AllPaletteBlocks { public static final BlockEntry NATURAL_SCORIA = REGISTRATE.block("natural_scoria", Block::new) .initialProperties(() -> Blocks.ANDESITE) + .tag(BlockTags.BASE_STONE_OVERWORLD) .onRegister(CreateRegistrate.blockVertexColors(new ScoriaVertexColor())) .loot((p, g) -> p.registerLootTable(g, RegistrateBlockLootTables.droppingWithSilkTouch(g, SCORIA.get()))) .blockstate(palettesCubeAll()) From e91a15cf5feed8875bdad968d24211a3e3409a71 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 26 Mar 2021 15:25:42 -0700 Subject: [PATCH 4/4] Ejectors wind up again. --- .../block/depot/EjectorInstance.java | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java index bb269009c..8efdd3fcf 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java @@ -1,5 +1,7 @@ package com.simibubi.create.content.logistics.block.depot; +import net.minecraft.util.math.MathHelper; + import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; @@ -17,6 +19,8 @@ public class EjectorInstance extends ShaftInstance implements IDynamicInstance { protected final InstanceKey plate; + private float lastProgress = Float.NaN; + public EjectorInstance(InstancedTileRenderer dispatcher, EjectorTileEntity tile) { super(dispatcher, tile); this.tile = tile; @@ -29,21 +33,12 @@ public class EjectorInstance extends ShaftInstance implements IDynamicInstance { @Override public void beginFrame() { + float lidProgress = getLidProgress(); - if (tile.lidProgress.settled()) return; + if (MathHelper.epsilonEquals(lidProgress, lastProgress)) return; - pivotPlate(); - } - - private void pivotPlate() { - float lidProgress = tile.getLidProgress(AnimationTickHolder.getPartialTicks()); - float angle = lidProgress * 70; - - MatrixStack ms = new MatrixStack(); - - EjectorRenderer.applyLidAngle(tile, angle, MatrixStacker.of(ms).translate(getInstancePosition())); - - plate.getInstance().setTransform(ms); + pivotPlate(lidProgress); + lastProgress = lidProgress; } @Override @@ -57,4 +52,22 @@ public class EjectorInstance extends ShaftInstance implements IDynamicInstance { super.remove(); plate.delete(); } + + private void pivotPlate() { + pivotPlate(getLidProgress()); + } + + private float getLidProgress() { + return tile.getLidProgress(AnimationTickHolder.getPartialTicks()); + } + + private void pivotPlate(float lidProgress) { + float angle = lidProgress * 70; + + MatrixStack ms = new MatrixStack(); + + EjectorRenderer.applyLidAngle(tile, angle, MatrixStacker.of(ms).translate(getInstancePosition())); + + plate.getInstance().setTransform(ms); + } }