Yurim64

UncolossalChest

May 3rd, 2021 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.10 KB | None | 0 0
  1. package com.ike.tenchest.chest.uncolossalchest;
  2.  
  3. import com.ike.tenchest.Blocks;
  4. import com.ike.tenchest.TenChest;
  5. import net.minecraft.block.*;
  6. import net.minecraft.entity.monster.piglin.PiglinTasks;
  7. import net.minecraft.entity.player.PlayerEntity;
  8. import net.minecraft.fluid.FluidState;
  9. import net.minecraft.fluid.Fluids;
  10. import net.minecraft.inventory.container.ChestContainer;
  11. import net.minecraft.inventory.container.SimpleNamedContainerProvider;
  12. import net.minecraft.item.BlockItemUseContext;
  13. import net.minecraft.particles.ParticleTypes;
  14. import net.minecraft.pathfinding.PathType;
  15. import net.minecraft.state.BooleanProperty;
  16. import net.minecraft.state.DirectionProperty;
  17. import net.minecraft.state.StateContainer;
  18. import net.minecraft.state.properties.BlockStateProperties;
  19. import net.minecraft.stats.Stats;
  20. import net.minecraft.tileentity.ChestTileEntity;
  21. import net.minecraft.tileentity.EnderChestTileEntity;
  22. import net.minecraft.tileentity.TileEntity;
  23. import net.minecraft.tileentity.TileEntityMerger;
  24. import net.minecraft.util.*;
  25. import net.minecraft.util.math.BlockPos;
  26. import net.minecraft.util.math.BlockRayTraceResult;
  27. import net.minecraft.util.math.shapes.ISelectionContext;
  28. import net.minecraft.util.math.shapes.VoxelShape;
  29. import net.minecraft.util.text.ITextComponent;
  30. import net.minecraft.util.text.TranslationTextComponent;
  31. import net.minecraft.world.IBlockReader;
  32. import net.minecraft.world.IWorld;
  33. import net.minecraft.world.World;
  34. import net.minecraftforge.api.distmarker.Dist;
  35. import net.minecraftforge.api.distmarker.OnlyIn;
  36.  
  37. import java.util.Random;
  38.  
  39. /**
  40.  * @author Ike
  41.  * @version 1.0A
  42.  **/
  43. public class UncolossalChest extends AbstractChestBlock<UncolossalChestTileEntity> implements IWaterLoggable {
  44.     public static final DirectionProperty FACING = HorizontalBlock.FACING;
  45.     public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
  46.     protected static final VoxelShape SHAPE = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 14.0D, 15.0D);
  47.     private static final ITextComponent CONTAINER_TITLE = new TranslationTextComponent("container.chest");
  48.  
  49.     public UncolossalChest(AbstractBlock.Properties p_i48403_1_) {
  50.         super(p_i48403_1_, () -> {
  51.             return Blocks.uncolossalChestType;
  52.         });
  53.         this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, Boolean.valueOf(false)));
  54.         this.setRegistryName(TenChest.MODID, "uncolossal_chest");
  55.         Blocks.BLOCKS.add(this);
  56.     }
  57.  
  58.     @OnlyIn(Dist.CLIENT)
  59.     public TileEntityMerger.ICallbackWrapper<? extends ChestTileEntity> combine(BlockState p_225536_1_, World p_225536_2_, BlockPos p_225536_3_, boolean p_225536_4_) {
  60.         return TileEntityMerger.ICallback::acceptNone;
  61.     }
  62.  
  63.     public VoxelShape getShape(BlockState p_220053_1_, IBlockReader p_220053_2_, BlockPos p_220053_3_, ISelectionContext p_220053_4_) {
  64.         return SHAPE;
  65.     }
  66.  
  67.     public BlockRenderType getRenderShape(BlockState p_149645_1_) {
  68.         return BlockRenderType.ENTITYBLOCK_ANIMATED;
  69.     }
  70.  
  71.     public BlockState getStateForPlacement(BlockItemUseContext p_196258_1_) {
  72.         FluidState fluidstate = p_196258_1_.getLevel().getFluidState(p_196258_1_.getClickedPos());
  73.         return this.defaultBlockState().setValue(FACING, p_196258_1_.getHorizontalDirection().getOpposite()).setValue(WATERLOGGED, Boolean.valueOf(fluidstate.getType() == Fluids.WATER));
  74.     }
  75.  
  76.     public ActionResultType use(BlockState p_225533_1_, World p_225533_2_, BlockPos p_225533_3_, PlayerEntity p_225533_4_, Hand p_225533_5_, BlockRayTraceResult p_225533_6_) {
  77.         TileEntity tileentity = p_225533_2_.getBlockEntity(p_225533_3_);
  78.         if (tileentity instanceof UncolossalChestTileEntity) {
  79.             BlockPos blockpos = p_225533_3_.above();
  80.             if (p_225533_2_.getBlockState(blockpos).isRedstoneConductor(p_225533_2_, blockpos)) {
  81.                 return ActionResultType.sidedSuccess(p_225533_2_.isClientSide);
  82.             } else if (p_225533_2_.isClientSide) {
  83.                 return ActionResultType.SUCCESS;
  84.             } else {
  85.                 UncolossalChestTileEntity uncolossalChestTileEntity = (UncolossalChestTileEntity) tileentity;
  86.                 //enderchestinventory.setActiveChest(enderchesttileentity);
  87.                 p_225533_4_.openMenu(new SimpleNamedContainerProvider((p_226928_1_, p_226928_2_, p_226928_3_) -> {
  88.                     return ChestContainer.threeRows(p_226928_1_, p_226928_2_, uncolossalChestTileEntity);
  89.                 }, CONTAINER_TITLE));
  90.                 p_225533_4_.awardStat(Stats.OPEN_CHEST);
  91.                 PiglinTasks.angerNearbyPiglins(p_225533_4_, true);
  92.                 return ActionResultType.CONSUME;
  93.             }
  94.         } else {
  95.             return ActionResultType.sidedSuccess(p_225533_2_.isClientSide);
  96.         }
  97.     }
  98.  
  99.     public TileEntity newBlockEntity(IBlockReader p_196283_1_) {
  100.         return new UncolossalChestTileEntity();
  101.     }
  102.  
  103.     @OnlyIn(Dist.CLIENT)
  104.     public void animateTick(BlockState p_180655_1_, World p_180655_2_, BlockPos p_180655_3_, Random p_180655_4_) {
  105.         for (int i = 0; i < 3; ++i) {
  106.             int j = p_180655_4_.nextInt(2) * 2 - 1;
  107.             int k = p_180655_4_.nextInt(2) * 2 - 1;
  108.             double d0 = (double) p_180655_3_.getX() + 0.5D + 0.25D * (double) j;
  109.             double d1 = (double) ((float) p_180655_3_.getY() + p_180655_4_.nextFloat());
  110.             double d2 = (double) p_180655_3_.getZ() + 0.5D + 0.25D * (double) k;
  111.             double d3 = (double) (p_180655_4_.nextFloat() * (float) j);
  112.             double d4 = ((double) p_180655_4_.nextFloat() - 0.5D) * 0.125D;
  113.             double d5 = (double) (p_180655_4_.nextFloat() * (float) k);
  114.             p_180655_2_.addParticle(ParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5);
  115.         }
  116.  
  117.     }
  118.  
  119.     public BlockState rotate(BlockState p_185499_1_, Rotation p_185499_2_) {
  120.         return p_185499_1_.setValue(FACING, p_185499_2_.rotate(p_185499_1_.getValue(FACING)));
  121.     }
  122.  
  123.     public BlockState mirror(BlockState p_185471_1_, Mirror p_185471_2_) {
  124.         return p_185471_1_.rotate(p_185471_2_.getRotation(p_185471_1_.getValue(FACING)));
  125.     }
  126.  
  127.     protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> p_206840_1_) {
  128.         p_206840_1_.add(FACING, WATERLOGGED);
  129.     }
  130.  
  131.     public FluidState getFluidState(BlockState p_204507_1_) {
  132.         return p_204507_1_.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(p_204507_1_);
  133.     }
  134.  
  135.     public BlockState updateShape(BlockState p_196271_1_, Direction p_196271_2_, BlockState p_196271_3_, IWorld p_196271_4_, BlockPos p_196271_5_, BlockPos p_196271_6_) {
  136.         if (p_196271_1_.getValue(WATERLOGGED)) {
  137.             p_196271_4_.getLiquidTicks().scheduleTick(p_196271_5_, Fluids.WATER, Fluids.WATER.getTickDelay(p_196271_4_));
  138.         }
  139.  
  140.         return super.updateShape(p_196271_1_, p_196271_2_, p_196271_3_, p_196271_4_, p_196271_5_, p_196271_6_);
  141.     }
  142.  
  143.     public boolean isPathfindable(BlockState p_196266_1_, IBlockReader p_196266_2_, BlockPos p_196266_3_, PathType p_196266_4_) {
  144.         return false;
  145.     }
  146. }
Add Comment
Please, Sign In to add comment