Merge branch 'master' into mc1.15/dev

This commit is contained in:
simibubi 2020-05-15 02:06:28 +02:00
commit c501de8c21
6 changed files with 89 additions and 30 deletions

View file

@ -26,6 +26,7 @@ import com.simibubi.create.modules.logistics.block.transposer.TransposerBlock;
import net.minecraft.block.AbstractPressurePlateBlock;
import net.minecraft.block.AbstractRailBlock;
import net.minecraft.block.BellBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@ -33,6 +34,7 @@ import net.minecraft.block.CarpetBlock;
import net.minecraft.block.DoorBlock;
import net.minecraft.block.FenceGateBlock;
import net.minecraft.block.FlowerPotBlock;
import net.minecraft.block.HorizontalBlock;
import net.minecraft.block.HorizontalFaceBlock;
import net.minecraft.block.LadderBlock;
import net.minecraft.block.RedstoneDiodeBlock;
@ -42,6 +44,7 @@ import net.minecraft.block.TorchBlock;
import net.minecraft.block.WallTorchBlock;
import net.minecraft.block.material.PushReaction;
import net.minecraft.state.properties.AttachFace;
import net.minecraft.state.properties.BellAttachment;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
@ -145,6 +148,8 @@ public class BlockMovementTraits {
return true;
if (block instanceof CarpetBlock)
return true;
if (block instanceof BellBlock)
return true;
return false;
}
@ -198,6 +203,16 @@ public class BlockMovementTraits {
return direction == state.get(NozzleBlock.FACING).getOpposite();
if (block instanceof EngineBlock)
return direction == state.get(EngineBlock.HORIZONTAL_FACING).getOpposite();
if (block instanceof BellBlock) {
BellAttachment attachment = state.get(BlockStateProperties.BELL_ATTACHMENT);
if (attachment == BellAttachment.FLOOR) {
return direction == Direction.DOWN;
}
if (attachment == BellAttachment.CEILING) {
return direction == Direction.UP;
}
return direction == state.get(HorizontalBlock.HORIZONTAL_FACING);
}
return false;
}

View file

@ -13,6 +13,7 @@ import com.simibubi.create.modules.contraptions.components.contraptions.chassis.
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock;
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope;
import net.minecraft.block.BellBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.HorizontalFaceBlock;
@ -20,6 +21,8 @@ import net.minecraft.block.SlabBlock;
import net.minecraft.block.StairsBlock;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.properties.AttachFace;
import net.minecraft.state.properties.BellAttachment;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.state.properties.Half;
import net.minecraft.state.properties.SlabType;
import net.minecraft.util.Direction;
@ -79,11 +82,18 @@ public class StructureTransform {
* horizontal axes
*/
public BlockState apply(BlockState state) {
if (rotationAxis == Axis.Y)
return state.rotate(rotation);
Block block = state.getBlock();
if (rotationAxis == Axis.Y) {
if (block instanceof BellBlock) {
if (state.get(BlockStateProperties.BELL_ATTACHMENT) == BellAttachment.DOUBLE_WALL) {
state = state.with(BlockStateProperties.BELL_ATTACHMENT, BellAttachment.SINGLE_WALL);
}
return state.with(HorizontalFaceBlock.HORIZONTAL_FACING, rotation.rotate(state.get(HorizontalFaceBlock.HORIZONTAL_FACING)));
}
return state.rotate(rotation);
}
if (block instanceof AbstractChassisBlock)
return rotateChassis(state);

View file

@ -8,6 +8,7 @@ import com.simibubi.create.AllEntities;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllPackets;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.modules.contraptions.components.contraptions.BlockMovementTraits;
import com.simibubi.create.modules.schematics.ISpecialEntityItemRequirement;
import com.simibubi.create.modules.schematics.ItemRequirement;
import com.simibubi.create.modules.schematics.ItemRequirement.ItemUseType;
@ -154,11 +155,20 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat
BlockPos pos2 = hangingPosition.offset(getFacingDirection().getOpposite());
if (!world.isAreaLoaded(pos, 0) || !world.isAreaLoaded(pos2, 0))
return true;
if (world.isAirBlock(pos) && world.isAirBlock(pos2))
if (!isValidFace(world, pos2, getFacingDirection()) && !isValidFace(world, pos, getFacingDirection().getOpposite()))
return false;
return world.getEntitiesInAABBexcluding(this, getBoundingBox(), e -> e instanceof SuperGlueEntity).isEmpty();
}
public static boolean isValidFace(World world, BlockPos pos, Direction direction) {
if (!BlockMovementTraits.movementNecessary(world, pos))
return false;
if (BlockMovementTraits.notSupportive(world.getBlockState(pos), direction)) {
return false;
}
return true;
}
@Override
public boolean canBeCollidedWith() {
return true;

View file

@ -78,7 +78,7 @@ public class SuperGlueRenderer extends EntityRenderer<SuperGlueEntity> {
return false;
BlockPos pos = entity.hangingPosition;
BlockPos pos2 = pos.offset(entity.getFacingDirection().getOpposite());
return entity.world.isAirBlock(pos) != entity.world.isAirBlock(pos2);
return !SuperGlueEntity.isValidFace(entity.world, pos2, entity.getFacingDirection()) || !SuperGlueEntity.isValidFace(entity.world, pos, entity.getFacingDirection().getOpposite());
}
private void initQuads() {

View file

@ -66,6 +66,7 @@ public class DeployerFakePlayer extends FakePlayer {
return new StringTextComponent(Lang.translate("block.deployer.damage_source_name"));
}
@Override
@OnlyIn(Dist.CLIENT)
public float getEyeHeight(Pose poseIn) {
return 0;

View file

@ -1,6 +1,7 @@
package com.simibubi.create.modules.contraptions.components.deployer;
import static net.minecraftforge.eventbus.api.Event.Result.DENY;
import static net.minecraftforge.eventbus.api.Event.Result.DEFAULT;
import java.util.ArrayList;
import java.util.List;
@ -47,7 +48,7 @@ import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock;
import net.minecraftforge.eventbus.api.Event.Result;
import net.minecraftforge.eventbus.api.Event;
public class DeployerHandler {
@ -72,8 +73,10 @@ public class DeployerHandler {
@Override
public BlockState getBlockState(BlockPos position) {
if (rayMode && (pos.offset(face.getOpposite(), 3).equals(position)
|| pos.offset(face.getOpposite(), 1).equals(position)))
if (rayMode && (pos.offset(face.getOpposite(), 3)
.equals(position)
|| pos.offset(face.getOpposite(), 1)
.equals(position)))
return Blocks.BEDROCK.getDefaultState();
return world.getBlockState(position);
}
@ -81,13 +84,16 @@ public class DeployerHandler {
static boolean shouldActivate(ItemStack held, World world, BlockPos targetPos) {
if (held.getItem() instanceof BlockItem)
if (!world.getBlockState(targetPos).getMaterial().isReplaceable())
if (!world.getBlockState(targetPos)
.getMaterial()
.isReplaceable())
return false;
if (held.getItem() instanceof BucketItem) {
BucketItem bucketItem = (BucketItem) held.getItem();
Fluid fluid = bucketItem.getFluid();
if (fluid != Fluids.EMPTY && world.getFluidState(targetPos).getFluid() == fluid)
if (fluid != Fluids.EMPTY && world.getFluidState(targetPos)
.getFluid() == fluid)
return false;
}
@ -95,11 +101,13 @@ public class DeployerHandler {
}
static void activate(DeployerFakePlayer player, Vec3d vec, BlockPos clickedPos, Vec3d extensionVector, Mode mode) {
Multimap<String, AttributeModifier> attributeModifiers =
player.getHeldItemMainhand().getAttributeModifiers(EquipmentSlotType.MAINHAND);
player.getAttributes().applyAttributeModifiers(attributeModifiers);
Multimap<String, AttributeModifier> attributeModifiers = player.getHeldItemMainhand()
.getAttributeModifiers(EquipmentSlotType.MAINHAND);
player.getAttributes()
.applyAttributeModifiers(attributeModifiers);
activateInner(player, vec, clickedPos, extensionVector, mode);
player.getAttributes().removeAttributeModifiers(attributeModifiers);
player.getAttributes()
.removeAttributeModifiers(attributeModifiers);
}
private static void activateInner(DeployerFakePlayer player, Vec3d vec, BlockPos clickedPos, Vec3d extensionVector,
@ -160,22 +168,24 @@ public class DeployerHandler {
BlockState clickedState = world.getBlockState(clickedPos);
Direction face = result.getFace();
if (face == null)
face = Direction.getFacingFromVector(extensionVector.x, extensionVector.y, extensionVector.z).getOpposite();
face = Direction.getFacingFromVector(extensionVector.x, extensionVector.y, extensionVector.z)
.getOpposite();
// Left click
if (mode == Mode.PUNCH) {
LeftClickBlock event = ForgeHooks.onLeftClickBlock(player, clickedPos, face);
if (event.isCanceled())
return;
if (!world.isBlockModifiable(player, clickedPos))
return;
if (world.extinguishFire(player, clickedPos, face))
return;
if (clickedState.isAir(world, clickedPos)) {
if (clickedState.getRenderShape(world, clickedPos)
.isEmpty()) {
player.blockBreakingProgress = null;
return;
}
if (event.getUseBlock() != Result.DENY)
LeftClickBlock event = ForgeHooks.onLeftClickBlock(player, clickedPos, face);
if (event.isCanceled())
return;
if (world.extinguishFire(player, clickedPos, face))
return;
if (event.getUseBlock() != DENY)
clickedState.onBlockClicked(world, clickedPos, player);
if (stack.isEmpty())
return;
@ -193,6 +203,10 @@ public class DeployerHandler {
player.blockBreakingProgress = null;
return;
}
if (progress <= 0) {
player.blockBreakingProgress = null;
return;
}
if ((int) (before * 10) != (int) (progress * 10))
world.sendBlockBreakProgress(player.getEntityId(), clickedPos, (int) (progress * 10));
@ -202,25 +216,33 @@ public class DeployerHandler {
// Right click
ItemUseContext itemusecontext = new ItemUseContext(player, hand, result);
Event.Result useBlock = DENY;
Event.Result useItem = DEFAULT;
if (!clickedState.getRenderShape(world, clickedPos)
.isEmpty()) {
RightClickBlock event = ForgeHooks.onRightClickBlock(player, hand, clickedPos, face);
useBlock = event.getUseBlock();
useItem = event.getUseItem();
}
// Item has custom active use
if (event.getUseItem() != DENY) {
if (useItem != DENY) {
ActionResultType actionresult = stack.onItemUseFirst(itemusecontext);
if (actionresult != ActionResultType.PASS)
return;
}
boolean holdingSomething = !player.getHeldItemMainhand().isEmpty();
boolean holdingSomething = !player.getHeldItemMainhand()
.isEmpty();
boolean flag1 =
!(player.isSneaking() && holdingSomething) || (stack.doesSneakBypassUse(world, clickedPos, player));
// Use on block
if (event.getUseBlock() != DENY && flag1 && clickedState.onUse(world, player, hand, result) == ActionResultType.SUCCESS)
if (useBlock != DENY && flag1 && clickedState.onUse(world, player, hand, result) == ActionResultType.SUCCESS)
return;
if (stack.isEmpty())
return;
if (event.getUseItem() == DENY)
if (useItem == DENY)
return;
if (item instanceof BlockItem && !clickedState.isReplaceable(new BlockItemUseContext(itemusecontext)))
return;
@ -258,7 +280,8 @@ public class DeployerHandler {
if (stack.isFood())
player.spawnedItemEffects = stack.copy();
if (!player.getActiveItemStack().isEmpty())
if (!player.getActiveItemStack()
.isEmpty())
player.setHeldItem(hand, stack.onItemUseFinish(world, player));
player.resetActiveHand();