Skip to content

Commit

Permalink
Add separate block entity types for infinite dispensers and droppers
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 authored and Patbox committed Nov 15, 2024
1 parent 215ca43 commit c9599e6
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/main/java/xyz/nucleoid/extras/lobby/NEBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ public class NEBlocks {

public static final BlockEntityType<LaunchPadBlockEntity> LAUNCH_PAD_ENTITY = FabricBlockEntityTypeBuilder.create(LaunchPadBlockEntity::new, GOLD_LAUNCH_PAD, IRON_LAUNCH_PAD).build();
public static final BlockEntityType<ContributorStatueBlockEntity> CONTRIBUTOR_STATUE_ENTITY = FabricBlockEntityTypeBuilder.create(ContributorStatueBlockEntity::new, CONTRIBUTOR_STATUE).build();
public static final BlockEntityType<InfiniteDispenserBlockEntity> INFINITE_DISPENSER_ENTITY = FabricBlockEntityTypeBuilder.create(InfiniteDispenserBlockEntity::new, INFINITE_DISPENSER).build();
public static final BlockEntityType<InfiniteDropperBlockEntity> INFINITE_DROPPER_ENTITY = FabricBlockEntityTypeBuilder.create(InfiniteDropperBlockEntity::new, INFINITE_DROPPER).build();
public static final BlockEntityType<TateroidBlockEntity> TATEROID_ENTITY = FabricBlockEntityTypeBuilder.create(TateroidBlockEntity::new, TATEROID, RED_TATEROID, ORANGE_TATEROID, YELLOW_TATEROID, GREEN_TATEROID, BLUE_TATEROID, PURPLE_TATEROID).build();
public static final BlockEntityType<DaylightDetectorTaterBlockEntity> DAYLIGHT_DETECTOR_TATER_ENTITY = FabricBlockEntityTypeBuilder.create(DaylightDetectorTaterBlockEntity::new, DAYLIGHT_DETECTOR_TATER, INVERTED_DAYLIGHT_DETECTOR_TATER).build();
public static final BlockEntityType<BellTaterBlockEntity> BELL_TATER_ENTITY = FabricBlockEntityTypeBuilder.create(BellTaterBlockEntity::new, BELL_TATER).build();
Expand Down Expand Up @@ -544,6 +546,8 @@ public static void register() {

registerBlockEntity("launch_pad", LAUNCH_PAD_ENTITY);
registerBlockEntity("contributor_statue", CONTRIBUTOR_STATUE_ENTITY);
registerBlockEntity("infinite_dispenser", INFINITE_DISPENSER_ENTITY);
registerBlockEntity("infinite_dropper", INFINITE_DROPPER_ENTITY);
registerBlockEntity("tateroid", TATEROID_ENTITY);
registerBlockEntity("daylight_detector_tater", DAYLIGHT_DETECTOR_TATER_ENTITY);
registerBlockEntity("bell_tater", BELL_TATER_ENTITY);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package xyz.nucleoid.extras.lobby.block;

import eu.pb4.polymer.core.api.block.PolymerBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.dispenser.DispenserBehavior;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.DispenserBlockEntity;
import net.minecraft.item.ItemStack;
Expand All @@ -13,6 +15,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldEvents;
import net.minecraft.world.event.GameEvent;
import xyz.nucleoid.extras.lobby.NEBlocks;
import xyz.nucleoid.packettweaker.PacketContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -24,12 +27,20 @@ public InfiniteDispenserBlock(Settings settings) {
super(settings);
}

protected Block getVirtualBlock() {
return Blocks.DISPENSER;
}

protected BlockEntityType<? extends DispenserBlockEntity> getBlockEntityType() {
return NEBlocks.INFINITE_DISPENSER_ENTITY;
}

@Override
protected void dispense(ServerWorld world, BlockState state, BlockPos pos) {
DispenserBlockEntity blockEntity = world.getBlockEntity(pos, BlockEntityType.DISPENSER).orElse(null);
DispenserBlockEntity blockEntity = world.getBlockEntity(pos, this.getBlockEntityType()).orElse(null);

if (blockEntity == null) {
LOGGER.warn("Ignoring dispensing attempt for Infinite Dispenser without matching block entity at {}", pos);
LOGGER.warn("Ignoring dispensing attempt for " + this.getName().getString() + " without matching block entity at {}", pos);
} else {
BlockPointer pointer = new BlockPointer(world, pos, state, blockEntity);

Expand All @@ -51,8 +62,11 @@ protected void dispense(ServerWorld world, BlockState state, BlockPos pos) {

@Override
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
return Blocks.DISPENSER.getDefaultState()
.with(FACING, state.get(FACING))
.with(TRIGGERED, state.get(TRIGGERED));
return this.getVirtualBlock().getStateWithProperties(state);
}

@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new InfiniteDispenserBlockEntity(pos, state);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package xyz.nucleoid.extras.lobby.block;

import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.DispenserBlockEntity;
import net.minecraft.util.math.BlockPos;
import xyz.nucleoid.extras.lobby.NEBlocks;

public class InfiniteDispenserBlockEntity extends DispenserBlockEntity {
protected InfiniteDispenserBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
}

public InfiniteDispenserBlockEntity(BlockPos pos, BlockState state) {
this(NEBlocks.INFINITE_DISPENSER_ENTITY, pos, state);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package xyz.nucleoid.extras.lobby.block;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.dispenser.DispenserBehavior;
import net.minecraft.block.dispenser.ItemDispenserBehavior;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.DropperBlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.DispenserBlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import xyz.nucleoid.packettweaker.PacketContext;
import xyz.nucleoid.extras.lobby.NEBlocks;

public class InfiniteDropperBlock extends InfiniteDispenserBlock {
private static final DispenserBehavior BEHAVIOR = new ItemDispenserBehavior();
Expand All @@ -19,17 +21,21 @@ public InfiniteDropperBlock(Settings settings) {
}

@Override
protected DispenserBehavior getBehaviorForItem(World world, ItemStack stack) {
return BEHAVIOR;
protected Block getVirtualBlock() {
return Blocks.DROPPER;
}

protected BlockEntityType<? extends DispenserBlockEntity> getBlockEntityType() {
return NEBlocks.INFINITE_DROPPER_ENTITY;
}

@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new DropperBlockEntity(pos, state);
protected DispenserBehavior getBehaviorForItem(World world, ItemStack stack) {
return BEHAVIOR;
}

@Override
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
return Blocks.DROPPER.getDefaultState();
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new InfiniteDropperBlockEntity(pos, state);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package xyz.nucleoid.extras.lobby.block;

import net.minecraft.block.BlockState;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import xyz.nucleoid.extras.lobby.NEBlocks;

public class InfiniteDropperBlockEntity extends InfiniteDispenserBlockEntity {
public InfiniteDropperBlockEntity(BlockPos pos, BlockState state) {
super(NEBlocks.INFINITE_DROPPER_ENTITY, pos, state);
}

@Override
protected Text getContainerName() {
return Text.translatable("container.dropper");
}
}

0 comments on commit c9599e6

Please sign in to comment.