Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.20 KB | None | 0 0
  1. public class PoweredFurnaceEntity extends AbstractFurnaceBlockEntity {
  2.     protected PoweredFurnaceEntity() {
  3.         super(MachineMod.POWERED_FURNACE_ENTITY, RecipeType.SMELTING);
  4.     }
  5.  
  6.     @Override
  7.     protected Text getContainerName() {
  8.         return new TranslatableText("machines.powered_furnace_entity", new Object[0]);
  9.     }
  10.  
  11.     @Override
  12.     protected Container createContainer(int i, PlayerInventory playerInventory) {
  13.         return new FurnaceContainer(i, playerInventory, this, this.propertyDelegate);
  14.     }
  15.  
  16.  
  17.  
  18.     @Override
  19.     public void tick() {
  20.         List<BlockPos> positions = Arrays.asList(pos.up(), pos.down(), pos.north(), pos.south(), pos.east(), pos.west());
  21.         Predicate<BlockPos> isLitEngine = pos -> world.getBlockState(pos).getBlock() instanceof Engine
  22.                 && world.getBlockState(pos).get(Engine.LIT);
  23.  
  24.         if (positions.stream().anyMatch(isLitEngine)) {
  25.             world.setBlockState(getPos(), world.getBlockState(pos).with(AbstractFurnaceBlock.LIT, true));
  26.             super.tick();
  27.         } else {
  28.             world.setBlockState(getPos(), world.getBlockState(pos).with(AbstractFurnaceBlock.LIT, false));
  29.         }
  30.     }
  31.  
  32.     @Override
  33.     protected int getCookTime() {
  34.         return (int) (0.7 * super.getCookTime());
  35.     }
  36.  
  37. }
  38.  
  39. public class PoweredFurnace extends AbstractFurnaceBlock {
  40.     protected PoweredFurnace(Settings settings) {
  41.         super(settings);
  42.     }
  43.  
  44.     @Override
  45.     protected void openContainer(World world, BlockPos pos, PlayerEntity player) {
  46.         BlockEntity blockEntity = world.getBlockEntity(pos);
  47.         if (blockEntity instanceof PoweredFurnaceEntity) {
  48.             player.openContainer((NameableContainerProvider) blockEntity);
  49.             player.incrementStat(Stats.INTERACT_WITH_FURNACE);
  50.         }
  51.  
  52.     }
  53.  
  54.     @Override
  55.     public BlockEntity createBlockEntity(BlockView view) {
  56.         return new PoweredFurnaceEntity();
  57.     }
  58.  
  59.     @Environment(EnvType.CLIENT)
  60.     @Override
  61.     public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
  62.         if (state.get(LIT)) {
  63.             double d = (double)pos.getX() + 0.5D;
  64.             double e = pos.getY();
  65.             double f = (double)pos.getZ() + 0.5D;
  66.             if (random.nextDouble() < 0.1D) {
  67.                 world.playSound(d, e, f, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
  68.             }
  69.  
  70.             Direction direction = state.get(FACING);
  71.             Direction.Axis axis = direction.getAxis();
  72.             double g = 0.52D;
  73.             double h = random.nextDouble() * 0.6D - 0.3D;
  74.             double i = axis == Direction.Axis.X ? (double)direction.getOffsetX() * 0.52D : h;
  75.             double j = random.nextDouble() * 6.0D / 16.0D;
  76.             double k = axis == Direction.Axis.Z ? (double)direction.getOffsetZ() * 0.52D : h;
  77.             world.addParticle(ParticleTypes.SMOKE, d + i, e + j, f + k, 0.0D, 0.0D, 0.0D);
  78.             world.addParticle(ParticleTypes.FLAME, d + i, e + j, f + k, 0.0D, 0.0D, 0.0D);
  79.         }
  80.     }
  81.  
  82.     @Override
  83.     public int getLuminance(BlockState state) {
  84.         return state.get(LIT) ? 15 : super.getLuminance(state);
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement