Java Code Examples for net.minecraft.world.World#getBlockEntity()
The following examples show how to use
net.minecraft.world.World#getBlockEntity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OxygenCollectorBlock.java From Galacticraft-Rewoven with MIT License | 6 votes |
@Override public void randomDisplayTick(BlockState blockState_1, World world, BlockPos pos, Random random_1) { BlockEntity blockEntity = world.getBlockEntity(pos); if (!(blockEntity instanceof OxygenCollectorBlockEntity)) { return; } OxygenCollectorBlockEntity collector = (OxygenCollectorBlockEntity) blockEntity; if (collector.collectionAmount > 0) { for (int particleCount = 0; particleCount < 10; particleCount++) { Random random = world.random; for (int int_1 = 0; int_1 < 32; ++int_1) { world.addParticle( new DustParticleEffect(0.9f, 0.9f, 1.0f, 1.0F), pos.getX() + 0.5D, (random.nextFloat() - 0.5D) * 0.5D + /*random.nextDouble() * 2.0D*/ 0.5D, pos.getZ() + 0.5D, random.nextGaussian(), 0.0D, random.nextGaussian()); } } } }
Example 2
Source File: DropperBlock_craftingMixin.java From carpet-extra with GNU Lesser General Public License v3.0 | 6 votes |
@Override public int getComparatorOutput(BlockState blockState_1, World world_1, BlockPos blockPos_1) { if (CarpetExtraSettings.autoCraftingDropper) { BlockPos front = blockPos_1.offset(world_1.getBlockState(blockPos_1).get(DispenserBlock.FACING)); if (world_1.getBlockState(front).getBlock() == Blocks.CRAFTING_TABLE) { DispenserBlockEntity dispenserBlockEntity_1 = (DispenserBlockEntity) world_1.getBlockEntity(blockPos_1); if (dispenserBlockEntity_1 != null) { int filled = 0; for (ItemStack stack : ((DispenserBlockEntityInterface) dispenserBlockEntity_1).getInventory()) { if (!stack.isEmpty()) filled++; } return (filled * 15) / 9; } } } return super.getComparatorOutput(blockState_1, world_1, blockPos_1); }
Example 3
Source File: CarpetDispenserBehaviours.java From carpet-extra with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack) { if (!CarpetExtraSettings.dispensersPlayRecords) return super.dispenseSilently(source, stack); Direction direction = source.getBlockState().get(DispenserBlock.FACING); BlockPos pos = source.getBlockPos().offset(direction); World world = source.getWorld(); BlockState state = world.getBlockState(pos); if (state.getBlock() == Blocks.JUKEBOX) { JukeboxBlockEntity jukebox = (JukeboxBlockEntity) world.getBlockEntity(pos); if (jukebox != null) { ItemStack itemStack = jukebox.getRecord(); ((JukeboxBlock) state.getBlock()).setRecord(world, pos, state, stack); world.playLevelEvent(null, 1010, pos, Item.getRawId(stack.getItem())); return itemStack; } } return super.dispenseSilently(source, stack); }
Example 4
Source File: CoalGeneratorBlock.java From Galacticraft-Rewoven with MIT License | 6 votes |
@Environment(EnvType.CLIENT) @Override public void randomDisplayTick(BlockState state, World world, BlockPos blockPos_1, Random rand) { if (world.getBlockEntity(blockPos_1) instanceof CoalGeneratorBlockEntity && ((CoalGeneratorBlockEntity) world.getBlockEntity(blockPos_1)).status == CoalGeneratorBlockEntity.CoalGeneratorStatus.ACTIVE || ((CoalGeneratorBlockEntity) world.getBlockEntity(blockPos_1)).status == CoalGeneratorBlockEntity.CoalGeneratorStatus.WARMING) { double x = (double) blockPos_1.getX() + 0.5D; double y = blockPos_1.getY(); double z = (double) blockPos_1.getZ() + 0.5D; if (rand.nextDouble() < 0.1D) { world.playSound(x, y, z, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false); } Direction direction_1 = state.get(FACING); Direction.Axis direction$Axis_1 = direction_1.getAxis(); double d = rand.nextDouble() * 0.6D - 0.3D; double xo = direction$Axis_1 == Direction.Axis.X ? (double) direction_1.getOffsetX() * 0.52D : d; double yo = rand.nextDouble() * 6.0D / 16.0D; double zo = direction$Axis_1 == Direction.Axis.Z ? (double) direction_1.getOffsetZ() * 0.52D : d; world.addParticle(ParticleTypes.SMOKE, x + xo, y + yo, z + zo, 0.0D, 0.0D, 0.0D); world.addParticle(ParticleTypes.FLAME, x + xo, y + yo, z + zo, 0.0D, 0.0D, 0.0D); } }
Example 5
Source File: CoalGeneratorBlock.java From Galacticraft-Rewoven with MIT License | 6 votes |
@Override public void onBreak(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) { super.onBreak(world, blockPos, blockState, playerEntity); BlockEntity blockEntity = world.getBlockEntity(blockPos); if (blockEntity != null) { if (blockEntity instanceof CoalGeneratorBlockEntity) { CoalGeneratorBlockEntity coalGeneratorBlockEntity = (CoalGeneratorBlockEntity) blockEntity; for (int i = 0; i < coalGeneratorBlockEntity.getInventory().getSize(); i++) { ItemStack itemStack = coalGeneratorBlockEntity.getInventory().getStack(i); if (itemStack != null) { world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack)); } } } } }
Example 6
Source File: EnergyStorageModuleBlock.java From Galacticraft-Rewoven with MIT License | 6 votes |
@Override public void onBreak(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) { super.onBreak(world, blockPos, blockState, playerEntity); BlockEntity blockEntity = world.getBlockEntity(blockPos); if (blockEntity != null) { if (blockEntity instanceof EnergyStorageModuleBlockEntity) { EnergyStorageModuleBlockEntity be = (EnergyStorageModuleBlockEntity) blockEntity; for (int i = 0; i < be.getInventory().getSize(); i++) { ItemStack itemStack = be.getInventory().getStack(i); if (itemStack != null) { world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack)); } } } } }
Example 7
Source File: RefineryBlock.java From Galacticraft-Rewoven with MIT License | 6 votes |
@Override public void onBreak(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) { super.onBreak(world, blockPos, blockState, playerEntity); BlockEntity blockEntity = world.getBlockEntity(blockPos); if (blockEntity != null) { if (blockEntity instanceof RefineryBlockEntity) { RefineryBlockEntity refineryBlockEntity = (RefineryBlockEntity) blockEntity; for (int i = 0; i < refineryBlockEntity.getInventory().getSize(); i++) { ItemStack itemStack = refineryBlockEntity.getInventory().getStack(i); if (itemStack != null) { world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack)); } } } } }
Example 8
Source File: ElectricCompressorBlock.java From Galacticraft-Rewoven with MIT License | 6 votes |
@Override public void onBreak(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) { super.onBreak(world, blockPos, blockState, playerEntity); BlockEntity blockEntity = world.getBlockEntity(blockPos); if (blockEntity != null) { if (blockEntity instanceof ElectricCompressorBlockEntity) { ElectricCompressorBlockEntity be = (ElectricCompressorBlockEntity) blockEntity; for (int i = 0; i < be.getInventory().getSize(); i++) { ItemStack itemStack = be.getInventory().getStack(i); if (!itemStack.isEmpty()) { world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack.copy())); } } } } }
Example 9
Source File: CompressorBlock.java From Galacticraft-Rewoven with MIT License | 6 votes |
@Override public void onBreak(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) { super.onBreak(world, blockPos, blockState, playerEntity); BlockEntity blockEntity = world.getBlockEntity(blockPos); if (blockEntity != null) { if (blockEntity instanceof CompressorBlockEntity) { CompressorBlockEntity be = (CompressorBlockEntity) blockEntity; for (int i = 0; i < be.getInventory().getSize(); i++) { ItemStack itemStack = be.getInventory().getStack(i); if (!itemStack.isEmpty()) { world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack.copy())); } } } } }
Example 10
Source File: CircuitFabricatorBlock.java From Galacticraft-Rewoven with MIT License | 6 votes |
@Override public void onBreak(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) { super.onBreak(world, blockPos, blockState, playerEntity); BlockEntity blockEntity = world.getBlockEntity(blockPos); if (blockEntity != null) { if (blockEntity instanceof CircuitFabricatorBlockEntity) { CircuitFabricatorBlockEntity circuitFabricatorBlockEntity = (CircuitFabricatorBlockEntity) blockEntity; for (int i = 0; i < circuitFabricatorBlockEntity.getInventory().getSize(); i++) { ItemStack itemStack = circuitFabricatorBlockEntity.getInventory().getStack(i); if (itemStack != null) { world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack)); } } } } }
Example 11
Source File: BasicSolarPanelBlock.java From Galacticraft-Rewoven with MIT License | 6 votes |
private void dropInventory(World world, BlockPos blockPos) { BlockEntity blockEntity = world.getBlockEntity(blockPos); if (blockEntity != null) { if (blockEntity instanceof BasicSolarPanelBlockEntity) { BasicSolarPanelBlockEntity basicSolarPanelBlockEntity = (BasicSolarPanelBlockEntity) blockEntity; for (int i = 0; i < basicSolarPanelBlockEntity.getInventory().getSize(); i++) { ItemStack itemStack = basicSolarPanelBlockEntity.getInventory().getStack(i); if (itemStack != null) { world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack)); } } } } }
Example 12
Source File: OxygenCollectorBlock.java From Galacticraft-Rewoven with MIT License | 6 votes |
@Override public void onBreak(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) { super.onBreak(world, blockPos, blockState, playerEntity); BlockEntity blockEntity = world.getBlockEntity(blockPos); if (blockEntity != null) { if (blockEntity instanceof OxygenCollectorBlockEntity) { OxygenCollectorBlockEntity be = (OxygenCollectorBlockEntity) blockEntity; for (int i = 0; i < be.getInventory().getSize(); i++) { ItemStack itemStack = be.getInventory().getStack(i); if (itemStack != null) { world.spawnEntity(new ItemEntity(world, blockPos.getX(), blockPos.getY() + 1, blockPos.getZ(), itemStack)); } } } } }
Example 13
Source File: BasicSolarPanelPartBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public ActionResult onUse(BlockState blockState_1, World world_1, BlockPos blockPos_1, PlayerEntity playerEntity_1, Hand hand_1, BlockHitResult blockHitResult_1) { BlockEntity partEntity = world_1.getBlockEntity(blockPos_1); if (world_1.isAir(blockPos_1) || !(partEntity instanceof BasicSolarPanelPartBlockEntity)) { return ActionResult.SUCCESS; } if (world_1.isClient) return ActionResult.SUCCESS; BlockPos basePos = ((BasicSolarPanelPartBlockEntity) partEntity).basePos; BlockState base = world_1.getBlockState(basePos); Block baseBlock = base.getBlock(); return ((BasicSolarPanelBlock) baseBlock).onUse(base, world_1, basePos, playerEntity_1, hand_1, blockHitResult_1); }
Example 14
Source File: TinyPumpkinBlock.java From the-hallow with MIT License | 5 votes |
@SuppressWarnings("deprecation") @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { BlockEntity be = world.getBlockEntity(pos); if (be instanceof TinyPumpkinBlockEntity) { return ((TinyPumpkinBlockEntity) be).use(player, hand, hit); } return ActionResult.PASS; }
Example 15
Source File: TinyPumpkinBlock.java From the-hallow with MIT License | 5 votes |
@SuppressWarnings("deprecation") @Override public void onBlockRemoved(BlockState state1, World world, BlockPos pos, BlockState state2, boolean flag) { if (state1.getBlock() != state2.getBlock()) { BlockEntity be = world.getBlockEntity(pos); if (be instanceof TinyPumpkinBlockEntity) { ItemScatterer.spawn(world, pos, ((TinyPumpkinBlockEntity) be).getAllItems()); world.updateHorizontalAdjacent(pos, this); } super.onBlockRemoved(state1, world, pos, state2, flag); } }
Example 16
Source File: InfusionPillarBlock.java From the-hallow with MIT License | 5 votes |
public InfusionAltarBlockEntity getAltar(World world, BlockPos blockPos) { for (Direction direction : HorizontalFacingBlock.FACING.getValues()) { BlockPos offsetPos = blockPos.offset(direction, 3); if (world.getBlockState(offsetPos).getBlock() == HallowedBlocks.INFUSION_ALTAR_BLOCK) { InfusionAltarBlockEntity altarEntity = (InfusionAltarBlockEntity) world.getBlockEntity(offsetPos); if (altarEntity != null) { return altarEntity; } } } return null; }
Example 17
Source File: InfusionPillarBlock.java From the-hallow with MIT License | 5 votes |
@SuppressWarnings("deprecation") @Override public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) { InfusionPillarBlockEntity pillarEntity = (InfusionPillarBlockEntity) world.getBlockEntity(blockPos); if (pillarEntity != null) { if (playerEntity.getStackInHand(hand).isEmpty()) { playerEntity.inventory.insertStack(pillarEntity.takeStack()); } else { playerEntity.setStackInHand(hand, pillarEntity.putStack(playerEntity.getStackInHand(hand))); } } return ActionResult.SUCCESS; }
Example 18
Source File: InfusionAltarBlock.java From the-hallow with MIT License | 5 votes |
@SuppressWarnings("deprecation") @Override public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) { InfusionAltarBlockEntity altarEntity = (InfusionAltarBlockEntity) world.getBlockEntity(blockPos); if (playerEntity.isSneaking()) { if (altarEntity != null) { getLinkedPillars(altarEntity); getCombinedInventory(altarEntity); Optional<InfusionRecipe> recipe = world.getRecipeManager().getFirstMatch(InfusionRecipe.Type.INSTANCE, combinedInventory, world); if (recipe.isPresent()) { if (world.isClient()) { createParticles(altarEntity); createSound(altarEntity); } if (!altarEntity.storedStack.isEmpty()) { createDrop(altarEntity, recipe.get().getOutput()); clearAllStacks(altarEntity); } else { altarEntity.storedStack = recipe.get().getOutput().copy(); clearPillarStacks(altarEntity); } } } } else { if (altarEntity != null) { if (playerEntity.getStackInHand(hand).isEmpty()) { playerEntity.inventory.offerOrDrop(world, altarEntity.takeStack()); } else { playerEntity.setStackInHand(hand, altarEntity.putStack(playerEntity.getStackInHand(hand))); } } } return ActionResult.SUCCESS; }
Example 19
Source File: PistonBlock_movableTEMixin.java From fabric-carpet with MIT License | 5 votes |
@Inject(method = "move", at = @At(value = "INVOKE", shift = At.Shift.BEFORE, target = "Ljava/util/List;size()I", ordinal = 4),locals = LocalCapture.CAPTURE_FAILHARD) private void onMove(World world_1, BlockPos blockPos_1, Direction direction_1, boolean boolean_1, CallbackInfoReturnable<Boolean> cir, BlockPos blockPos_2, PistonHandler pistonHandler_1, Map map_1, List<BlockPos> list_1, List<BlockState> list_2, List list_3, int int_2, BlockState[] blockStates_1, Direction direction_2) { //Get the blockEntities and remove them from the world before any magic starts to happen if (CarpetSettings.movableBlockEntities) { list1_BlockEntities.set(Lists.newArrayList()); for (int i = 0; i < list_1.size(); ++i) { BlockPos blockpos = list_1.get(i); BlockEntity blockEntity = (list_2.get(i).getBlock().hasBlockEntity()) ? world_1.getBlockEntity(blockpos) : null; list1_BlockEntities.get().add(blockEntity); if (blockEntity != null) { //hopefully this call won't have any side effects in the future, such as dropping all the BlockEntity's items //we want to place this same(!) BlockEntity object into the world later when the movement stops again world_1.removeBlockEntity(blockpos); blockEntity.markDirty(); } } } }
Example 20
Source File: DropperBlock_craftingMixin.java From carpet-extra with GNU Lesser General Public License v3.0 | 4 votes |
@Inject(method = "dispense", at = @At("HEAD"), cancellable = true) private void tryCraft(World world_1, BlockPos blockPos_1, CallbackInfo ci) { if (!CarpetExtraSettings.autoCraftingDropper) return; BlockPos front = blockPos_1.offset(world_1.getBlockState(blockPos_1).get(DispenserBlock.FACING)); if (world_1.getBlockState(front).getBlock() != Blocks.CRAFTING_TABLE) return; DispenserBlockEntity dispenserBlockEntity_1 = (DispenserBlockEntity) world_1.getBlockEntity(blockPos_1); if (dispenserBlockEntity_1 == null) return; CraftingInventory craftingInventory = new CraftingInventory(new VoidContainer(), 3, 3); for (int i=0; i < 9; i++) craftingInventory.setInvStack(i, dispenserBlockEntity_1.getInvStack(i)); CraftingRecipe recipe = world_1.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, craftingInventory, world_1).orElse(null); if (recipe == null) return; // crafting it Vec3d target = new Vec3d(front).add(0.5, 0.2, 0.5); ItemStack result = recipe.craft(craftingInventory); spawn(world_1, target.x, target.y, target.z, result); // copied from CraftingResultSlot.onTakeItem() DefaultedList<ItemStack> defaultedList_1 = world_1.getRecipeManager().getRemainingStacks(RecipeType.CRAFTING, craftingInventory, world_1); for(int int_1 = 0; int_1 < defaultedList_1.size(); ++int_1) { ItemStack itemStack_2 = dispenserBlockEntity_1.getInvStack(int_1); ItemStack itemStack_3 = defaultedList_1.get(int_1); if (!itemStack_2.isEmpty()) { dispenserBlockEntity_1.takeInvStack(int_1, 1); itemStack_2 = dispenserBlockEntity_1.getInvStack(int_1); } if (!itemStack_3.isEmpty()) { if (itemStack_2.isEmpty()) { dispenserBlockEntity_1.setInvStack(int_1, itemStack_3); } else if (ItemStack.areItemsEqualIgnoreDamage(itemStack_2, itemStack_3) && ItemStack.areTagsEqual(itemStack_2, itemStack_3)) { itemStack_3.increment(itemStack_2.getCount()); dispenserBlockEntity_1.setInvStack(int_1, itemStack_3); } else { spawn(world_1, target.x, target.y, target.z, itemStack_3); } } } Vec3d vec = new Vec3d(blockPos_1).add(0.5, 0.5, 0.5); ServerWorld world = (ServerWorld) world_1; world.playSound(null, blockPos_1, SoundEvents.ENTITY_VILLAGER_WORK_MASON, SoundCategory.BLOCKS, 0.2f, 2.0f); ci.cancel(); }