diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 7ffc0e1cc..76c10722a 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -407,16 +407,16 @@ a3a11524cd3515fc01d905767b4b7ea782adaf03 assets/create/blockstates/yellow_seat.j 7f39521b211441f5c3e06d60c5978cebe16cacfb assets/create/blockstates/zinc_block.json b7181bcd8182b2f17088e5aa881f374c9c65470c assets/create/blockstates/zinc_ore.json 768a724d6c921cb92790364cf7a692fe8742a885 assets/create/lang/en_ud.json -74c0dd6af2ffc332fe1459f9c3fbfc9371eb2507 assets/create/lang/en_us.json -97f7b6e61707a003e907ee166911ca106f0439d6 assets/create/lang/unfinished/de_de.json +363aca3d1194218b7d48fcec33d36c1b9c555e4e assets/create/lang/en_us.json +616063d3a66a6e56ccee1584ce38986d363908df assets/create/lang/unfinished/de_de.json aa49b660299817b148b362f9f5c357906de8df90 assets/create/lang/unfinished/es_es.json -072cb64aac3feba48a2ca7e481cda325d7648b0f assets/create/lang/unfinished/es_mx.json +c85b6b95decefd03769debc9d6a2ac1bff481dd4 assets/create/lang/unfinished/es_mx.json 5463fcf22674ed540ce860358508fbac609c49d1 assets/create/lang/unfinished/fr_fr.json 7fbd50f2325711f3a2fd086d8307ff1afb577220 assets/create/lang/unfinished/it_it.json ff653860335529694629c7cabb7953afebc6fea3 assets/create/lang/unfinished/ja_jp.json 332556b3f5364601e872431fab0fe3cdf40ac373 assets/create/lang/unfinished/ko_kr.json -cc8e5eb4c2ea1390a215d12462d54f761e076c64 assets/create/lang/unfinished/nl_nl.json -88fd1b02799e8d1392be7df529803321e334033d assets/create/lang/unfinished/pt_br.json +8043c3d6d26835c784d1163282a9d4a391a6c8dd assets/create/lang/unfinished/nl_nl.json +c562a4d350d9abb40e83ab4a78851eda3886dfe9 assets/create/lang/unfinished/pt_br.json f58b4e50ef5042aad6b254db7ff8c219f06b9ea3 assets/create/lang/unfinished/ru_ru.json e9e4cfbc8ef54b6c04ae77c776dfa7e546d05e02 assets/create/lang/unfinished/zh_cn.json eb17617bb14d0ffac000f86d6f9aa23429e8f4c3 assets/create/lang/unfinished/zh_tw.json @@ -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/assets/create/lang/en_us.json b/src/generated/resources/assets/create/lang/en_us.json index ebf8add75..9585a0a26 100644 --- a/src/generated/resources/assets/create/lang/en_us.json +++ b/src/generated/resources/assets/create/lang/en_us.json @@ -882,7 +882,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", @@ -897,12 +897,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.", @@ -978,7 +978,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 009935132..c4749347a 100644 --- a/src/generated/resources/assets/create/lang/unfinished/de_de.json +++ b/src/generated/resources/assets/create/lang/unfinished/de_de.json @@ -883,7 +883,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 812eca405..428eefcf9 100644 --- a/src/generated/resources/assets/create/lang/unfinished/es_mx.json +++ b/src/generated/resources/assets/create/lang/unfinished/es_mx.json @@ -883,7 +883,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", @@ -898,12 +898,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.", @@ -979,7 +979,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 b7f649cfa..365abe188 100644 --- a/src/generated/resources/assets/create/lang/unfinished/nl_nl.json +++ b/src/generated/resources/assets/create/lang/unfinished/nl_nl.json @@ -883,7 +883,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 54cd1250f..b73a1871e 100644 --- a/src/generated/resources/assets/create/lang/unfinished/pt_br.json +++ b/src/generated/resources/assets/create/lang/unfinished/pt_br.json @@ -883,7 +883,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/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/contraptions/components/deployer/DeployerMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java index 1fc78fa48..de30b0c0a 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 @@ -1,6 +1,16 @@ package com.simibubi.create.content.contraptions.components.deployer; +import java.util.Arrays; +import java.util.List; + +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; @@ -8,23 +18,33 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov 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.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.NBTHelper; +import com.simibubi.create.foundation.item.ItemHelper.ExtractionCountMode; +import com.simibubi.create.foundation.utility.BlockHelper; +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.vector.Vector3d; +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 org.apache.commons.lang3.tuple.Pair; - -import javax.annotation.Nullable; -import java.util.Arrays; -import java.util.List; +import net.minecraftforge.event.ForgeEventFactory; +import net.minecraftforge.items.IItemHandler; public class DeployerMovementBehaviour extends MovementBehaviour { @@ -52,6 +72,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); + Vector3d facingVec = Vector3d.of(context.state.get(DeployerBlock.FACING) .getDirectionVec()); facingVec = context.rotation.apply(facingVec); @@ -62,6 +88,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.create(world.getRegistryKey(), 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) @@ -109,6 +190,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/curiosities/ChromaticCompoundItem.java b/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundItem.java index f81cd9cba..3b7d0ae2d 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); @@ -132,11 +130,13 @@ public class ChromaticCompoundItem extends Item { 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..76887104e --- /dev/null +++ b/src/main/java/com/simibubi/create/content/curiosities/NoGravMagicalDohickyItem.java @@ -0,0 +1,68 @@ +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.vector.Vector3d; +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; + Vector3d pos = entity.getPositionVec(); + CompoundNBT persistentData = entity.getPersistentData(); + + if (world.isRemote) { + if (world.rand.nextFloat() < getIdleParticleChance(entity)) { + Vector3d 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")) { + Vector3d basemotion = new Vector3d(0, 1, 0); + world.addParticle(ParticleTypes.FLASH, pos.x, pos.y, pos.z, 0, 0, 0); + for (int i = 0; i < 20; i++) { + Vector3d 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 25a38db43..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.vector.Vector3d; -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; - Vector3d pos = entity.getPositionVec(); - - if (world.isRemote && entity.hasNoGravity()) { - if (world.rand.nextFloat() < MathHelper.clamp(entity.getItem().getCount() - 10, 1, 100) / 64f) { - Vector3d 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")) { - Vector3d basemotion = new Vector3d(0, 1, 0); - world.addParticle(ParticleTypes.FLASH, pos.x, pos.y, pos.z, 0, 0, 0); - for (int i = 0; i < 20; i++) { - Vector3d 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 af71309fa..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.vector.Vector3d; -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; - Vector3d 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) { - Vector3d 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")) { - Vector3d basemotion = new Vector3d(0, 1, 0); - world.addParticle(ParticleTypes.FLASH, pos.x, pos.y, pos.z, 0, 0, 0); - for (int i = 0; i < 20; i++) { - Vector3d 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 12c79f672..e54dfc1ae 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 (!BlockHelper.hasBlockSolidSide(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 (!BlockHelper.hasBlockSolidSide(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 ec9fd955a..1b21ee48b 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 @@ -1,5 +1,12 @@ 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; + import com.simibubi.create.AllBlocks; import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.components.fan.AirCurrent; @@ -60,7 +67,7 @@ import java.util.List; */ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInformation { // , IAirCurrentSource { -// public AirCurrent airCurrent; + // public AirCurrent airCurrent; float pull; float push; @@ -91,7 +98,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; } @@ -177,7 +184,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; @@ -207,14 +214,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()) @@ -266,8 +273,8 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor } extractFromBelt(itemSpeed); -// if (getSpeed() != 0) -// airCurrent.tick(); + // if (getSpeed() != 0) + // airCurrent.tick(); } public void blockBelowChanged() { @@ -322,29 +329,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) { @@ -358,9 +376,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; @@ -408,10 +427,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(); } } @@ -720,47 +740,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 307b69fc5..ad735a27d 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 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); + } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorTileEntity.java index aab950b29..dd1dd8c31 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorTileEntity.java @@ -58,6 +58,8 @@ public class EjectorTileEntity extends KineticTileEntity { DepotBehaviour depotBehaviour; EntityLauncher launcher; LerpedFloat lidProgress; + boolean powered; + boolean launch; State state; public enum State { @@ -71,6 +73,7 @@ public class EjectorTileEntity extends KineticTileEntity { .startWithValue(1); state = State.RETRACTING; launchedItems = new ArrayList<>(); + 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, 512); + 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 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()) 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 2b3c92e88..f1a956435 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,32 +3,23 @@ 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.foundation.utility.BlockHelper; 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 { @@ -129,46 +120,7 @@ public abstract class LaunchedItem { @Override void place(World world) { - // Piston - if (state.contains(BlockStateProperties.EXTENDED)) - state = state.with(BlockStateProperties.EXTENDED, Boolean.FALSE); - if (state.contains(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.getDimension().isUltrawarm() && 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.fromTag(state, 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 4b9c706d9..e06bbfec1 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 @@ -175,7 +175,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"); @@ -185,17 +185,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")); @@ -250,7 +250,7 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC compound.put("CurrentPos", NBTUtil.writeBlockPos(currentPos)); } } - + // Gui information compound.putFloat("Progress", schematicProgress); compound.putFloat("PaperProgress", bookPrintingProgress); @@ -260,17 +260,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)); @@ -375,11 +375,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); @@ -710,10 +712,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.contains(BlockStateProperties.BED_PART) && state.contains(BlockStateProperties.HORIZONTAL_FACING) && state.get(BlockStateProperties.BED_PART) == BedPart.FOOT) + if (state.contains(BlockStateProperties.BED_PART) && state.contains(BlockStateProperties.HORIZONTAL_FACING) + && state.get(BlockStateProperties.BED_PART) == BedPart.FOOT) toReplaceOther = world.getBlockState(pos.offset(state.get(BlockStateProperties.HORIZONTAL_FACING))); if (state.contains(BlockStateProperties.DOUBLE_BLOCK_HALF) && state.get(BlockStateProperties.DOUBLE_BLOCK_HALF) == DoubleBlockHalf.LOWER) @@ -726,11 +730,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)) @@ -741,10 +747,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; @@ -754,7 +762,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; @@ -851,7 +859,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 7803c2792..d2eaa4595 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 646dd02c1..8b89fcf4b 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java @@ -6,6 +6,9 @@ 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; @@ -17,12 +20,16 @@ import net.minecraft.fluid.FluidState; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.state.Property; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.SlabType; import net.minecraft.tags.BlockTags; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.particles.ParticleTypes; +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; @@ -32,6 +39,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 { @@ -194,9 +202,63 @@ public class BlockHelper { return hasBlockSolidSide(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.contains(BlockStateProperties.EXTENDED)) + state = state.with(BlockStateProperties.EXTENDED, Boolean.FALSE); + if (state.contains(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.getDimension().isUltrawarm() && 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.fromTag(tile.getBlockState(), data); + } + } + + try { + state.getBlock() + .onBlockPlacedBy(world, target, state, null, stack); + } catch (Exception e) { + } } public static boolean hasBlockSolidSide(BlockState p_220056_0_, IBlockReader p_220056_1_, BlockPos p_220056_2_, Direction p_220056_3_) { 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",