For the techies

- Fixed Deployers accepting held items from the back
- Deployers now set filters on blocks only by targeting any location on a correct side
- Fixed Schematics loaded for deployer printing not rotating block entity contents
This commit is contained in:
simibubi 2023-04-24 13:45:30 +02:00
parent f5ba751e6a
commit 5bf263f63c
5 changed files with 34 additions and 12 deletions

View file

@ -67,11 +67,13 @@ public class DeployerBlock extends DirectionalAxisKineticBlock implements IBE<De
@Override @Override
public InteractionResult onWrenched(BlockState state, UseOnContext context) { public InteractionResult onWrenched(BlockState state, UseOnContext context) {
Vec3 normal = Vec3.atLowerCornerOf(state.getValue(FACING)
.getNormal());
Vec3 location = context.getClickLocation() Vec3 location = context.getClickLocation()
.subtract(Vec3.atCenterOf(context.getClickedPos())) .subtract(Vec3.atCenterOf(context.getClickedPos())
.multiply(Vec3.atLowerCornerOf(state.getValue(FACING) .subtract(normal.scale(.5)))
.getNormal())); .multiply(normal);
if (location.length() > .25f) { if (location.length() > .75f) {
if (!context.getLevel().isClientSide) if (!context.getLevel().isClientSide)
withBlockEntityDo(context.getLevel(), context.getClickedPos(), DeployerBlockEntity::changeMode); withBlockEntityDo(context.getLevel(), context.getClickedPos(), DeployerBlockEntity::changeMode);
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
@ -110,11 +112,13 @@ public class DeployerBlock extends DirectionalAxisKineticBlock implements IBE<De
if (AllItems.WRENCH.isIn(heldByPlayer)) if (AllItems.WRENCH.isIn(heldByPlayer))
return InteractionResult.PASS; return InteractionResult.PASS;
Vec3 normal = Vec3.atLowerCornerOf(state.getValue(FACING)
.getNormal());
Vec3 location = hit.getLocation() Vec3 location = hit.getLocation()
.subtract(Vec3.atCenterOf(pos)) .subtract(Vec3.atCenterOf(pos)
.multiply(Vec3.atLowerCornerOf(state.getValue(FACING) .subtract(normal.scale(.5)))
.getNormal())); .multiply(normal);
if (hit.getDirection() != state.getValue(FACING) && location.length() < .25f) if (location.length() < .75f)
return InteractionResult.PASS; return InteractionResult.PASS;
if (worldIn.isClientSide) if (worldIn.isClientSide)
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;

View file

@ -112,7 +112,7 @@ public class SchematicPrinter {
StructureTransform transform = new StructureTransform(settings.getRotationPivot(), Direction.Axis.Y, StructureTransform transform = new StructureTransform(settings.getRotationPivot(), Direction.Axis.Y,
settings.getRotation(), settings.getMirror()); settings.getRotation(), settings.getMirror());
for (BlockEntity be : blockReader.blockEntities.values()) for (BlockEntity be : blockReader.getBlockEntities())
transform.apply(be); transform.apply(be);
printingEntityIndex = -1; printingEntityIndex = -1;

View file

@ -228,6 +228,10 @@ public class SchematicWorld extends WrappedWorld implements ServerLevelAccessor
public BoundingBox getBounds() { public BoundingBox getBounds() {
return bounds; return bounds;
} }
public Iterable<BlockEntity> getBlockEntities() {
return blockEntities.values();
}
public Iterable<BlockEntity> getRenderedBlockEntities() { public Iterable<BlockEntity> getRenderedBlockEntities() {
return renderedBlockEntities; return renderedBlockEntities;

View file

@ -6,17 +6,20 @@ import javax.annotation.Nullable;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform;
import com.simibubi.create.content.schematics.SchematicWorld; import com.simibubi.create.content.schematics.SchematicWorld;
import com.simibubi.create.content.schematics.item.SchematicItem; import com.simibubi.create.content.schematics.item.SchematicItem;
import com.simibubi.create.foundation.utility.WorldAttached; import com.simibubi.create.foundation.utility.WorldAttached;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.NbtUtils;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
@ -65,6 +68,11 @@ public class SchematicInstances {
StructurePlaceSettings settings = SchematicItem.getSettings(schematic); StructurePlaceSettings settings = SchematicItem.getSettings(schematic);
activeTemplate.placeInWorld(world, anchor, anchor, settings, wrapped.getRandom(), Block.UPDATE_CLIENTS); activeTemplate.placeInWorld(world, anchor, anchor, settings, wrapped.getRandom(), Block.UPDATE_CLIENTS);
StructureTransform transform = new StructureTransform(settings.getRotationPivot(), Direction.Axis.Y,
settings.getRotation(), settings.getMirror());
for (BlockEntity be : world.getBlockEntities())
transform.apply(be);
return world; return world;
} }

View file

@ -15,6 +15,7 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
@ -63,15 +64,20 @@ public class ValueSettingsInputHandler {
if (valueSettingsBehaviour.onlyVisibleWithWrench() if (valueSettingsBehaviour.onlyVisibleWithWrench()
&& !AllItemTags.WRENCH.matches(player.getItemInHand(hand))) && !AllItemTags.WRENCH.matches(player.getItemInHand(hand)))
continue; continue;
if (valueSettingsBehaviour.getSlotPositioning()instanceof ValueBoxTransform.Sided sidedSlot) if (valueSettingsBehaviour.getSlotPositioning()instanceof ValueBoxTransform.Sided sidedSlot) {
if (!sidedSlot.isSideActive(sbe.getBlockState(), ray.getDirection()))
continue;
sidedSlot.fromSide(ray.getDirection()); sidedSlot.fromSide(ray.getDirection());
if (!valueSettingsBehaviour.testHit(ray.getLocation())) }
boolean fakePlayer = player instanceof FakePlayer;
if (!valueSettingsBehaviour.testHit(ray.getLocation()) && !fakePlayer)
continue; continue;
event.setCanceled(true); event.setCanceled(true);
event.setCancellationResult(InteractionResult.SUCCESS); event.setCancellationResult(InteractionResult.SUCCESS);
if (!valueSettingsBehaviour.acceptsValueSettings()) { if (!valueSettingsBehaviour.acceptsValueSettings() || fakePlayer) {
valueSettingsBehaviour.onShortInteract(player, hand, ray.getDirection()); valueSettingsBehaviour.onShortInteract(player, hand, ray.getDirection());
return; return;
} }