diff --git a/src/main/java/com/atsuishio/superbwarfare/block/ContainerBlock.java b/src/main/java/com/atsuishio/superbwarfare/block/ContainerBlock.java index 80b6c5099..1d77435d1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/block/ContainerBlock.java +++ b/src/main/java/com/atsuishio/superbwarfare/block/ContainerBlock.java @@ -1,143 +1,58 @@ - package com.atsuishio.superbwarfare.block; -import com.atsuishio.superbwarfare.ModUtils; -import com.atsuishio.superbwarfare.init.ModBlockEntities; -import com.atsuishio.superbwarfare.init.ModEntities; -import com.atsuishio.superbwarfare.tools.ParticleTool; +import com.atsuishio.superbwarfare.block.entity.ContainerBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.MobSpawnType; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.DirectionProperty; -import net.minecraft.world.level.material.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.level.storage.loot.LootParams; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import javax.annotation.Nullable; -import java.util.Collections; -import java.util.List; +@SuppressWarnings("deprecation") public class ContainerBlock extends BaseEntityBlock implements SimpleWaterloggedBlock, EntityBlock { - public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; - public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; - public ContainerBlock() { - super(BlockBehaviour.Properties.of().sound(SoundType.METAL).strength(-1, 3600000).noCollission()); - this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, false)); - } + public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; + public static final BooleanProperty OPENED = BooleanProperty.create("opened"); - @Override - public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { + public ContainerBlock() { + super(BlockBehaviour.Properties.of().sound(SoundType.METAL).strength(3.0f).noCollission()); + this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(OPENED, false)); + } - return switch (state.getValue(FACING)) { - default -> box(0, 0, 0, 16, 1, 16); - case NORTH -> box(0, 0, 0, 16, 1, 16); - case EAST -> box(0, 0, 0, 16, 1, 16); - case WEST -> box(0, 0, 0, 16, 1, 16); - }; - } + @Override + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { + return state.getValue(OPENED) ? box(0, 0, 0, 16, 1, 16) : box(0, 0, 0, 16, 16, 16); + } + @Override + public RenderShape getRenderShape(BlockState state) { + return RenderShape.ENTITYBLOCK_ANIMATED; + } - @Override - public RenderShape getRenderShape(BlockState state) { - return RenderShape.ENTITYBLOCK_ANIMATED; - } + @Nullable + @Override + public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { + return new ContainerBlockEntity(blockPos, blockState); + } - @Nullable - @Override - public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { - return ModBlockEntities.CONTAINER.get().create(blockPos, blockState); - } + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + builder.add(FACING).add(OPENED); + } - @Override - public boolean propagatesSkylightDown(BlockState state, BlockGetter reader, BlockPos pos) { - return state.getFluidState().isEmpty(); - } - - @Override - public int getLightBlock(BlockState state, BlockGetter worldIn, BlockPos pos) { - return 0; - } - - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(FACING, WATERLOGGED); - } - - @Override - public BlockState getStateForPlacement(BlockPlaceContext context) { - boolean flag = context.getLevel().getFluidState(context.getClickedPos()).getType() == Fluids.WATER; - return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(WATERLOGGED, flag); - } - - public BlockState rotate(BlockState state, Rotation rot) { - return state.setValue(FACING, rot.rotate(state.getValue(FACING))); - } - - public BlockState mirror(BlockState state, Mirror mirrorIn) { - return state.rotate(mirrorIn.getRotation(state.getValue(FACING))); - } - - @Override - public FluidState getFluidState(BlockState state) { - return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); - } - - @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState facingState, LevelAccessor world, BlockPos currentPos, BlockPos facingPos) { - if (state.getValue(WATERLOGGED)) { - world.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); - } - return super.updateShape(state, facing, facingState, world, currentPos, facingPos); - } - - @Override - public List getDrops(BlockState state, LootParams.Builder builder) { - List dropsOriginal = super.getDrops(state, builder); - if (!dropsOriginal.isEmpty()) - return dropsOriginal; - return Collections.singletonList(new ItemStack(this, 1)); - } - - @Override - public void setPlacedBy(Level level, BlockPos pos, BlockState blockstate, LivingEntity entity, ItemStack itemstack) { - super.setPlacedBy(level, pos, blockstate, entity, itemstack); - ModUtils.queueServerWork(18, () -> { - if (!level.isClientSide()) - level.explode(null, pos.getX(), pos.getY() + 1, pos.getZ(), 0, Level.ExplosionInteraction.NONE); - if (level instanceof ServerLevel serverLevel) { - ParticleTool.sendParticle(serverLevel, ParticleTypes.EXPLOSION, pos.getX(), pos.getY() + 1, pos.getZ(), 40, 1.5, 1.5, 1.5, 1, false); - } - }); - ModUtils.queueServerWork(20, () -> { - level.setBlock(BlockPos.containing(pos.getX(), pos.getY(), pos.getZ()), Blocks.AIR.defaultBlockState(), 3); - if (level instanceof ServerLevel _level) { - Entity entityToSpawn = ModEntities.MK_42.get().spawn(_level, BlockPos.containing(pos.getX(), pos.getY(), pos.getZ()), MobSpawnType.MOB_SUMMONED); - if (entityToSpawn != null) { - entityToSpawn.setYRot(level.getRandom().nextFloat() * 360F); - } - } - }); - - } + @Override + public BlockState getStateForPlacement(BlockPlaceContext context) { + return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(OPENED, false); + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/block/listener/ClientListener.java b/src/main/java/com/atsuishio/superbwarfare/block/listener/ClientListener.java deleted file mode 100644 index d828c1151..000000000 --- a/src/main/java/com/atsuishio/superbwarfare/block/listener/ClientListener.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.atsuishio.superbwarfare.block.listener; - -import com.atsuishio.superbwarfare.ModUtils; -import com.atsuishio.superbwarfare.client.renderer.block.ContainerBlockEntityRenderer; -import com.atsuishio.superbwarfare.init.ModBlockEntities; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.event.EntityRenderersEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; - -@Mod.EventBusSubscriber(modid = ModUtils.MODID, bus = Mod.EventBusSubscriber.Bus.MOD) -public class ClientListener { - @OnlyIn(Dist.CLIENT) - @SubscribeEvent - public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) { - event.registerBlockEntityRenderer(ModBlockEntities.CONTAINER.get(), context -> new ContainerBlockEntityRenderer()); - } -} diff --git a/src/main/java/com/atsuishio/superbwarfare/client/ClientRenderHandler.java b/src/main/java/com/atsuishio/superbwarfare/client/ClientRenderHandler.java index 6bd0f9743..6cd9f209f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/ClientRenderHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/ClientRenderHandler.java @@ -1,8 +1,11 @@ package com.atsuishio.superbwarfare.client; +import com.atsuishio.superbwarfare.client.renderer.block.ContainerBlockEntityRenderer; import com.atsuishio.superbwarfare.client.tooltip.*; import com.atsuishio.superbwarfare.client.tooltip.component.*; +import com.atsuishio.superbwarfare.init.ModBlockEntities; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.EntityRenderersEvent; import net.minecraftforge.client.event.RegisterClientTooltipComponentFactoriesEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -19,4 +22,9 @@ public class ClientRenderHandler { event.register(SentinelImageComponent.class, ClientSentinelImageTooltip::new); } + @SubscribeEvent + public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) { + event.registerBlockEntityRenderer(ModBlockEntities.CONTAINER.get(), context -> new ContainerBlockEntityRenderer()); + } + } diff --git a/src/main/resources/assets/superbwarfare/models/displaysettings/container.item.json b/src/main/resources/assets/superbwarfare/models/displaysettings/container.item.json deleted file mode 100644 index ad5435701..000000000 --- a/src/main/resources/assets/superbwarfare/models/displaysettings/container.item.json +++ /dev/null @@ -1,124 +0,0 @@ -{ - "credit": "Made with Blockbench", - "parent": "builtin/entity", - "texture_size": [ - 128, - 128 - ], - "display": { - "thirdperson_righthand": { - "rotation": [ - 90, - 0, - 0 - ], - "translation": [ - 0, - -2, - -6 - ], - "scale": [ - 0.4, - 0.4, - 0.4 - ] - }, - "thirdperson_lefthand": { - "rotation": [ - 90, - 0, - 0 - ], - "translation": [ - 0, - -2, - -6 - ], - "scale": [ - 0.4, - 0.4, - 0.4 - ] - }, - "firstperson_righthand": { - "rotation": [ - -176.35, - 27.92, - -176.98 - ], - "translation": [ - -2, - 0, - 0 - ], - "scale": [ - 0.4, - 0.4, - 0.4 - ] - }, - "firstperson_lefthand": { - "rotation": [ - -176.35, - 27.92, - -176.98 - ], - "translation": [ - -2, - 0, - 0 - ], - "scale": [ - 0.4, - 0.4, - 0.4 - ] - }, - "ground": { - "translation": [ - 0, - -1.75, - 0 - ], - "scale": [ - 0.5, - 0.5, - 0.5 - ] - }, - "gui": { - "rotation": [ - -155, - -45, - 180 - ], - "translation": [ - 0, - -4.5, - 0 - ], - "scale": [ - 0.65, - 0.65, - 0.65 - ] - }, - "head": { - "translation": [ - 0, - -7, - 0 - ] - }, - "fixed": { - "translation": [ - 0, - -7.75, - 1 - ] - } - }, - "textures": { - "particle": "item/container" - } -} \ No newline at end of file diff --git a/src/main/resources/assets/superbwarfare/models/item/container.json b/src/main/resources/assets/superbwarfare/models/item/container.json index a29b43908..18f715db5 100644 --- a/src/main/resources/assets/superbwarfare/models/item/container.json +++ b/src/main/resources/assets/superbwarfare/models/item/container.json @@ -1,3 +1,124 @@ { - "parent": "superbwarfare:displaysettings/container.item" + "credit": "Made with Blockbench", + "parent": "builtin/entity", + "texture_size": [ + 128, + 128 + ], + "display": { + "thirdperson_righthand": { + "rotation": [ + 90, + 0, + 0 + ], + "translation": [ + 0, + -2, + -6 + ], + "scale": [ + 0.4, + 0.4, + 0.4 + ] + }, + "thirdperson_lefthand": { + "rotation": [ + 90, + 0, + 0 + ], + "translation": [ + 0, + -2, + -6 + ], + "scale": [ + 0.4, + 0.4, + 0.4 + ] + }, + "firstperson_righthand": { + "rotation": [ + -176.35, + 27.92, + -176.98 + ], + "translation": [ + -2, + 0, + 0 + ], + "scale": [ + 0.4, + 0.4, + 0.4 + ] + }, + "firstperson_lefthand": { + "rotation": [ + -176.35, + 27.92, + -176.98 + ], + "translation": [ + -2, + 0, + 0 + ], + "scale": [ + 0.4, + 0.4, + 0.4 + ] + }, + "ground": { + "translation": [ + 0, + -1.75, + 0 + ], + "scale": [ + 0.5, + 0.5, + 0.5 + ] + }, + "gui": { + "rotation": [ + -155, + -45, + 180 + ], + "translation": [ + 0, + -4.5, + 0 + ], + "scale": [ + 0.65, + 0.65, + 0.65 + ] + }, + "head": { + "translation": [ + 0, + -7, + 0 + ] + }, + "fixed": { + "translation": [ + 0, + -7.75, + 1 + ] + } + }, + "textures": { + "particle": "superbwarfare:block/container" + } } \ No newline at end of file