diff --git a/src/main/java/eu/midnightdust/motschen/decorative/block/Springboard.java b/src/main/java/eu/midnightdust/motschen/decorative/block/Springboard.java index a8ae7f5..95a4d60 100755 --- a/src/main/java/eu/midnightdust/motschen/decorative/block/Springboard.java +++ b/src/main/java/eu/midnightdust/motschen/decorative/block/Springboard.java @@ -3,7 +3,9 @@ package eu.midnightdust.motschen.decorative.block; import com.mojang.serialization.MapCodec; import eu.midnightdust.motschen.decorative.DecorativeMain; import eu.midnightdust.motschen.decorative.blockstates.Part; +import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplaySpringboardModel; import eu.pb4.factorytools.api.block.FactoryBlock; +import eu.pb4.polymer.virtualentity.api.ElementHolder; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -16,6 +18,8 @@ import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemStack; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.BlockSoundGroup; import net.minecraft.state.StateManager; import net.minecraft.state.property.EnumProperty; @@ -29,8 +33,7 @@ import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.BlockView; import net.minecraft.world.World; import net.minecraft.world.WorldView; - -import java.util.Objects; +import org.jetbrains.annotations.Nullable; public class Springboard extends HorizontalFacingBlock implements FactoryBlock { private static final VoxelShape NORTH_SHAPE_FRONT; @@ -41,21 +44,19 @@ public class Springboard extends HorizontalFacingBlock implements FactoryBlock { private static final VoxelShape EAST_SHAPE_BACK; private static final VoxelShape SOUTH_SHAPE_BACK; private static final VoxelShape WEST_SHAPE_BACK; - private static final EnumProperty PART = DecorativeMain.PART; + public static final EnumProperty PART = DecorativeMain.PART; public Springboard() { super(AbstractBlock.Settings.copy(Blocks.STONE).nonOpaque().sounds(BlockSoundGroup.STONE)); this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH).with(PART, Part.BACK)); } - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - ItemStack itemStack = player.getStackInHand(hand); + @Override + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { if (!world.isClient) { - if (itemStack.isEmpty() && hand==Hand.MAIN_HAND) { - if (state.get(PART) == Part.FRONT) { - if (player.getY() >= pos.getY() + 0.1 && player.squaredDistanceTo(pos.getX(), pos.getY(), pos.getZ()) <= 1.0) { - player.addStatusEffect(new StatusEffectInstance(StatusEffects.LEVITATION, 10, 10)); - return ActionResult.SUCCESS; - } + if (state.get(PART) == Part.FRONT) { + if (player.getY() >= pos.getY() + 0.1d && player.squaredDistanceTo(pos.getX()+0.5d, pos.getY()+0.5d, pos.getZ()+0.5d) <= 1.0d) { + player.addStatusEffect(new StatusEffectInstance(StatusEffects.LEVITATION, 10, 10)); + return ActionResult.SUCCESS; } } } @@ -261,4 +262,13 @@ public class Springboard extends HorizontalFacingBlock implements FactoryBlock { public BlockState getPolymerBlockState(BlockState state) { return Blocks.BARRIER.getDefaultState(); } + @Override + public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) { + return Blocks.IRON_BLOCK.getDefaultState(); + } + + @Override + public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) { + return new ItemDisplaySpringboardModel(initialBlockState); + } } diff --git a/src/main/java/eu/midnightdust/motschen/decorative/polymer/PolymerSupport.java b/src/main/java/eu/midnightdust/motschen/decorative/polymer/PolymerSupport.java index 2c77cb2..31d0818 100644 --- a/src/main/java/eu/midnightdust/motschen/decorative/polymer/PolymerSupport.java +++ b/src/main/java/eu/midnightdust/motschen/decorative/polymer/PolymerSupport.java @@ -16,5 +16,6 @@ public class PolymerSupport { ItemDisplayLampModel.initModels(); ItemDisplayPoolWallModel.initModels(); ItemDisplaySlidingDoorModel.initModels(); + ItemDisplaySpringboardModel.initModels(); } } diff --git a/src/main/java/eu/midnightdust/motschen/decorative/polymer/model/ItemDisplaySpringboardModel.java b/src/main/java/eu/midnightdust/motschen/decorative/polymer/model/ItemDisplaySpringboardModel.java new file mode 100644 index 0000000..ab6563d --- /dev/null +++ b/src/main/java/eu/midnightdust/motschen/decorative/polymer/model/ItemDisplaySpringboardModel.java @@ -0,0 +1,58 @@ +package eu.midnightdust.motschen.decorative.polymer.model; + +import eu.midnightdust.motschen.decorative.block.Springboard; +import eu.midnightdust.motschen.decorative.blockstates.Part; +import eu.midnightdust.motschen.decorative.config.DecorativeConfig; +import eu.pb4.factorytools.api.resourcepack.BaseItemProvider; +import eu.pb4.factorytools.api.virtualentity.BlockModel; +import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil; +import eu.pb4.polymer.virtualentity.api.attachment.BlockAwareAttachment; +import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment; +import eu.pb4.polymer.virtualentity.api.elements.ItemDisplayElement; +import net.minecraft.block.BlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.RotationAxis; +import net.minecraft.util.math.Vec3d; +import org.joml.Vector3f; + +import static eu.midnightdust.motschen.decorative.DecorativeMain.id; + +public class ItemDisplaySpringboardModel extends BlockModel { + private final ItemDisplayElement main; + private static ItemStack BACK; + private static ItemStack FRONT; + + public static void initModels() { + BACK = BaseItemProvider.requestModel(id("block/springboard_back")); + FRONT = BaseItemProvider.requestModel(id("block/springboard_front")); + } + + public ItemDisplaySpringboardModel(BlockState state) { + this.main = ItemDisplayElementUtil.createSimple(getModel(state)); + this.main.setDisplaySize(1, 1); + this.main.setScale(new Vector3f(1)); + //this.main.setOffset(new Vec3d(0d, 0.25d, 0d)); + this.main.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(getRotation(state))); + this.main.setViewRange(DecorativeConfig.viewDistance / 100f); + this.addElement(this.main); + } + + @Override + public void notifyUpdate(HolderAttachment.UpdateType updateType) { + if (updateType == BlockAwareAttachment.BLOCK_STATE_UPDATE) { + var state = this.blockState(); + this.main.setItem(getModel(state)); + this.main.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(getRotation(state))); + + this.tick(); + } + } + public ItemStack getModel(BlockState state) { + return state.get(Springboard.PART) == Part.BACK ? BACK : FRONT; + } + public float getRotation(BlockState state) { + return state.get(Springboard.FACING).getHorizontal() * -90 - 90; + } + +} +