mirror of
https://github.com/TeamMidnightDust/Decorative.git
synced 2025-12-15 12:35:10 +01:00
Choppin' the Log
- Chopping Logs now work on Polymer
This commit is contained in:
@@ -6,7 +6,6 @@ import eu.pb4.factorytools.api.block.FactoryBlock;
|
||||
import eu.pb4.polymer.virtualentity.api.ElementHolder;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.cauldron.CauldronBehavior;
|
||||
import net.minecraft.block.enums.BlockFace;
|
||||
import net.minecraft.component.ComponentMap;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.PotionContentsComponent;
|
||||
@@ -22,7 +21,6 @@ import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.IntProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
|
||||
@@ -64,7 +64,7 @@ public class CeilingFan extends BlockWithEntity implements BlockEntityProvider,
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return super.getPlacementState(itemPlacementContext).with(STAGE, CeilingFanStage.OFF);
|
||||
return this.getDefaultState().with(STAGE, CeilingFanStage.OFF);
|
||||
}
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
|
||||
|
||||
@@ -3,7 +3,9 @@ package eu.midnightdust.motschen.decorative.block;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import eu.midnightdust.motschen.decorative.block.blockentity.ChoppingLogBlockEntity;
|
||||
import eu.midnightdust.motschen.decorative.init.BlockEntities;
|
||||
import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayChoppingLogModel;
|
||||
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.BlockEntityProvider;
|
||||
@@ -15,20 +17,22 @@ import net.minecraft.block.HorizontalFacingBlock;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.block.enums.BlockFace;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
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.DirectionProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldView;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ChoppingLog extends BlockWithEntity implements BlockEntityProvider, FactoryBlock {
|
||||
private static final DirectionProperty FACING = HorizontalFacingBlock.FACING;
|
||||
public static final DirectionProperty FACING = HorizontalFacingBlock.FACING;
|
||||
|
||||
public ChoppingLog() {
|
||||
super(AbstractBlock.Settings.copy(Blocks.OAK_PLANKS).nonOpaque().sounds(BlockSoundGroup.WOOD));
|
||||
@@ -37,8 +41,7 @@ public class ChoppingLog extends BlockWithEntity implements BlockEntityProvider,
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return Objects.requireNonNull(super.getPlacementState(itemPlacementContext))
|
||||
.with(FACING, itemPlacementContext.getPlayerLookDirection().getOpposite());
|
||||
return this.getDefaultState().with(FACING, itemPlacementContext.getHorizontalPlayerFacing().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +76,28 @@ public class ChoppingLog extends BlockWithEntity implements BlockEntityProvider,
|
||||
// Polymer
|
||||
@Override
|
||||
public BlockState getPolymerBlockState(BlockState state) {
|
||||
return Blocks.BARRIER.getDefaultState();
|
||||
return switch (state.getBlock().getTranslationKey()) {
|
||||
case "block.decorative.oak_log_with_axe" -> Blocks.OAK_LOG.getDefaultState();
|
||||
case "block.decorative.spruce_log_with_axe" -> Blocks.SPRUCE_LOG.getDefaultState();
|
||||
case "block.decorative.birch_log_with_axe" -> Blocks.BIRCH_LOG.getDefaultState();
|
||||
case "block.decorative.acacia_log_with_axe" -> Blocks.ACACIA_LOG.getDefaultState();
|
||||
case "block.decorative.dark_oak_log_with_axe" -> Blocks.DARK_OAK_LOG.getDefaultState();
|
||||
case "block.decorative.jungle_log_with_axe" -> Blocks.JUNGLE_LOG.getDefaultState();
|
||||
case "block.decorative.warped_stem_with_axe" -> Blocks.WARPED_STEM.getDefaultState();
|
||||
case "block.decorative.crimson_stem_with_axe" -> Blocks.CRIMSON_STEM.getDefaultState();
|
||||
case "block.decorative.cherry_log_with_axe" -> Blocks.CHERRY_LOG.getDefaultState();
|
||||
case "block.decorative.mangrove_log_with_axe" -> Blocks.MANGROVE_LOG.getDefaultState();
|
||||
default -> Blocks.BARRIER.getDefaultState();
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) {
|
||||
return Blocks.STONE_BUTTON.getDefaultState().with(Properties.BLOCK_FACE, BlockFace.FLOOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) {
|
||||
return new ItemDisplayChoppingLogModel(initialBlockState, pos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ public class ChristmasLights extends HorizontalFacingBlock implements FactoryBlo
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return super.getPlacementState(itemPlacementContext)
|
||||
.with(FACING, itemPlacementContext.getPlayerLookDirection().getOpposite())
|
||||
return this.getDefaultState()
|
||||
.with(FACING, itemPlacementContext.getHorizontalPlayerFacing().getOpposite())
|
||||
.with(LIT, Boolean.FALSE);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public class DigitalClock extends BlockWithEntity implements BlockEntityProvider
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return super.getPlacementState(itemPlacementContext).with(FACING, itemPlacementContext.getPlayerLookDirection().getOpposite());
|
||||
return this.getDefaultState().with(FACING, itemPlacementContext.getHorizontalPlayerFacing().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -52,7 +52,7 @@ public class FireHydrant extends HorizontalFacingBlock implements FactoryBlock {
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return super.getPlacementState(itemPlacementContext).with(FACING, itemPlacementContext.getPlayerLookDirection().getOpposite());
|
||||
return this.getDefaultState().with(FACING, itemPlacementContext.getHorizontalPlayerFacing().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Guardrail extends HorizontalFacingBlock implements FactoryBlock {
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return super.getPlacementState(itemPlacementContext).with(FACING, itemPlacementContext.getPlayerLookDirection().getOpposite());
|
||||
return this.getDefaultState().with(FACING, itemPlacementContext.getHorizontalPlayerFacing().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,7 +39,8 @@ public class Lamp extends Block implements FactoryBlock {
|
||||
return this.getDefaultState().with(LIT, arg.getWorld().isReceivingRedstonePower(arg.getBlockPos()));
|
||||
}
|
||||
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
|
||||
world.setBlockState(pos, state.with(LIT, Boolean.valueOf(!state.get(LIT))));
|
||||
world.playSound(player, pos, SoundEvents.BLOCK_STONE_BUTTON_CLICK_ON, SoundCategory.BLOCKS, 0.2f, 0.5f);
|
||||
return ActionResult.SUCCESS;
|
||||
|
||||
@@ -51,7 +51,9 @@ public class OldTelevision extends HorizontalFacingBlock implements FactoryBlock
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return super.getPlacementState(itemPlacementContext).with(FACING, itemPlacementContext.getPlayerLookDirection().getOpposite()).with(PROGRAM, Program.OFF);
|
||||
return this.getDefaultState()
|
||||
.with(FACING, itemPlacementContext.getHorizontalPlayerFacing().getOpposite())
|
||||
.with(PROGRAM, Program.OFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -61,8 +61,8 @@ public class PoolSprinkler extends BlockWithEntity implements BlockEntityProvide
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return Objects.requireNonNull(super.getPlacementState(itemPlacementContext))
|
||||
.with(FACING, itemPlacementContext.getPlayerLookDirection().getOpposite())
|
||||
return this.getDefaultState()
|
||||
.with(FACING, itemPlacementContext.getHorizontalPlayerFacing().getOpposite())
|
||||
.with(POWERED, Boolean.FALSE);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class PoolWall extends HorizontalFacingBlock implements Waterloggable, Fa
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
BlockPos blockPos = ctx.getBlockPos();
|
||||
FluidState fluidState = ctx.getWorld().getFluidState(blockPos);
|
||||
BlockState blockState = this.getDefaultState().with(FACING, ctx.getPlayerLookDirection().getOpposite()).with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
|
||||
BlockState blockState = this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite()).with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
|
||||
return blockState.with(SHAPE, getPoolShape(blockState, ctx.getWorld(), blockPos));
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class RotatableBlock extends HorizontalFacingBlock implements PolymerText
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return super.getPlacementState(itemPlacementContext).with(FACING, itemPlacementContext.getPlayerLookDirection().getOpposite());
|
||||
return this.getDefaultState().with(FACING, itemPlacementContext.getHorizontalPlayerFacing().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -59,8 +59,8 @@ public class ShowerHead extends BlockWithEntity implements BlockEntityProvider,
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return super.getPlacementState(itemPlacementContext)
|
||||
.with(FACING, itemPlacementContext.getPlayerLookDirection().getOpposite())
|
||||
return this.getDefaultState()
|
||||
.with(FACING, itemPlacementContext.getHorizontalPlayerFacing().getOpposite())
|
||||
.with(POWERED, Boolean.FALSE);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,7 @@ public class Sign extends HorizontalFacingBlock implements FactoryBlock {
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return super.getPlacementState(itemPlacementContext)
|
||||
.with(FACING, itemPlacementContext.getPlayerLookDirection().getOpposite());
|
||||
return this.getDefaultState().with(FACING, itemPlacementContext.getHorizontalPlayerFacing().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -84,6 +84,6 @@ public class SlidingDoor extends DoorBlock implements FactoryBlock {
|
||||
// Polymer
|
||||
@Override
|
||||
public BlockState getPolymerBlockState(BlockState state) {
|
||||
return Blocks.BARRIER.getDefaultState();
|
||||
return state.get(OPEN) ? Blocks.STRUCTURE_VOID.getDefaultState() : Blocks.BARRIER.getDefaultState();
|
||||
}
|
||||
}
|
||||
@@ -63,8 +63,8 @@ public class Springboard extends HorizontalFacingBlock implements FactoryBlock {
|
||||
}
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return Objects.requireNonNull(super.getPlacementState(itemPlacementContext))
|
||||
.with(FACING, itemPlacementContext.getPlayerLookDirection())
|
||||
return this.getDefaultState()
|
||||
.with(FACING, itemPlacementContext.getHorizontalPlayerFacing().getOpposite())
|
||||
.with(PART, Part.BACK);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@ public class Television extends HorizontalFacingBlock implements FactoryBlock {
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return Objects.requireNonNull(super.getPlacementState(itemPlacementContext))
|
||||
.with(FACING, itemPlacementContext.getPlayerLookDirection().getOpposite())
|
||||
return this.getDefaultState()
|
||||
.with(FACING, itemPlacementContext.getHorizontalPlayerFacing().getOpposite())
|
||||
.with(PROGRAM, Program.OFF);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,8 +69,7 @@ public class WallClock extends BlockWithEntity implements BlockEntityProvider, F
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return Objects.requireNonNull(super.getPlacementState(itemPlacementContext))
|
||||
.with(FACING, itemPlacementContext.getPlayerLookDirection().getOpposite());
|
||||
return this.getDefaultState().with(FACING, itemPlacementContext.getHorizontalPlayerFacing().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -55,8 +55,7 @@ public class WaterPump extends HorizontalFacingBlock implements FactoryBlock {
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
|
||||
return Objects.requireNonNull(super.getPlacementState(itemPlacementContext))
|
||||
.with(FACING, itemPlacementContext.getPlayerLookDirection().getOpposite());
|
||||
return this.getDefaultState().with(FACING, itemPlacementContext.getHorizontalPlayerFacing().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,12 +7,12 @@ import static eu.midnightdust.motschen.decorative.DecorativeMain.id;
|
||||
import static eu.midnightdust.motschen.decorative.util.RegistryUtil.registerGarden;
|
||||
|
||||
public class LogsWithAxes {
|
||||
public static Block OakChoppingLog = new ChoppingLog();
|
||||
public static Block SpruceChoppingLog = new ChoppingLog();
|
||||
public static Block BirchChoppingLog = new ChoppingLog();
|
||||
public static Block AcaciaChoppingLog = new ChoppingLog();
|
||||
public static Block JungleChoppingLog = new ChoppingLog();
|
||||
public static Block DarkOakChoppingLog = new ChoppingLog();
|
||||
public static final Block OakChoppingLog = new ChoppingLog();
|
||||
public static final Block SpruceChoppingLog = new ChoppingLog();
|
||||
public static final Block BirchChoppingLog = new ChoppingLog();
|
||||
public static final Block AcaciaChoppingLog = new ChoppingLog();
|
||||
public static final Block JungleChoppingLog = new ChoppingLog();
|
||||
public static final Block DarkOakChoppingLog = new ChoppingLog();
|
||||
|
||||
public static void init() {
|
||||
registerGarden(id("oak_log_with_axe"), OakChoppingLog);
|
||||
|
||||
@@ -28,6 +28,7 @@ public class BathTireItem extends Item implements AutoModeledPolymerItem {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
|
||||
ItemStack itemStack = user.getStackInHand(hand);
|
||||
BlockHitResult hitResult = raycast(world, user, RaycastContext.FluidHandling.SOURCE_ONLY);
|
||||
|
||||
@@ -44,7 +44,8 @@ public class ItemDisplayBirdBathModel extends BlockModel {
|
||||
this.main.setViewRange(0.75f * (DecorativeConfig.viewDistance / 100f));
|
||||
this.addElement(this.main);
|
||||
|
||||
//int color = ColorUtil.convertRgbToArgb(world.getColor(pos, BiomeColors.WATER_COLOR));
|
||||
// TODO: Get actual biome color when it's implemented in Polymer
|
||||
// int baseColor = ColorUtil.getWaterColor(world, pos);
|
||||
int color = ColorUtil.convertRgbToArgb(4159204);
|
||||
WATER.applyComponentsFrom(ComponentMap.builder().add(DataComponentTypes.POTION_CONTENTS, new PotionContentsComponent(Optional.of(Potions.WATER), Optional.of(color), List.of())).build());
|
||||
this.water = ItemDisplayElementUtil.createSimple(WATER);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package eu.midnightdust.motschen.decorative.polymer.model;
|
||||
|
||||
import eu.midnightdust.motschen.decorative.block.ChoppingLog;
|
||||
import eu.midnightdust.motschen.decorative.config.DecorativeConfig;
|
||||
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.item.Items;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RotationAxis;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class ItemDisplayChoppingLogModel extends BlockModel {
|
||||
private final ItemDisplayElement main;
|
||||
public static ItemStack AXE = new ItemStack(Items.IRON_AXE);
|
||||
double axe_x;
|
||||
double axe_z;
|
||||
int rotation;
|
||||
|
||||
public ItemDisplayChoppingLogModel(BlockState state, BlockPos pos) {
|
||||
this.main = ItemDisplayElementUtil.createSimple(AXE);
|
||||
this.main.setDisplaySize(1, 1);
|
||||
this.main.setScale(new Vector3f(1.25f));
|
||||
|
||||
setupTranslation(state);
|
||||
this.main.setOffset(new Vec3d(this.axe_x, 0.9D, this.axe_z));
|
||||
this.main.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(this.rotation).rotateZ(2.792527f));
|
||||
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();
|
||||
setupTranslation(state);
|
||||
this.main.setOffset(new Vec3d(this.axe_x, 0.9D, this.axe_z));
|
||||
this.main.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(this.rotation).rotateZ(2.792527f));
|
||||
|
||||
this.tick();
|
||||
}
|
||||
}
|
||||
public void setupTranslation(BlockState state) {
|
||||
switch (state.get(ChoppingLog.FACING)) {
|
||||
case EAST -> {
|
||||
rotation = 180; axe_x = -0.3D; axe_z = 0.0D;
|
||||
}
|
||||
case SOUTH -> {
|
||||
rotation = 90; axe_x = 0.0D; axe_z = -0.3D;
|
||||
}
|
||||
case WEST -> {
|
||||
rotation = 0; axe_x = 0.3D; axe_z = 0.0D;
|
||||
}
|
||||
default -> {
|
||||
rotation = 270; axe_x = 0.0D; axe_z = 0.3D;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package eu.midnightdust.motschen.decorative.util;
|
||||
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class ColorUtil {
|
||||
public static int convertRgbToArgb(int rgb) {
|
||||
int red = 0xFF & (rgb >> 16);
|
||||
@@ -9,4 +12,8 @@ public class ColorUtil {
|
||||
|
||||
return (alpha << 24) | (red << 16) | (green << 8) | blue;
|
||||
}
|
||||
public static int getWaterColor(ServerWorld world, BlockPos pos) {
|
||||
var biome = world.getBiome(pos);
|
||||
return biome == null ? 4159204 : biome.value().getWaterColor();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user