fixed monster hoarder block entity

This commit is contained in:
Jörg Henke 2021-07-31 21:39:33 +02:00
parent 292c0746c1
commit 21923dac80
3 changed files with 14 additions and 11 deletions

View File

@ -18,19 +18,22 @@ import net.minecraft.world.World;
public class MonsterHoarderBlockEntity extends BlockEntity { public class MonsterHoarderBlockEntity extends BlockEntity {
private float suckradius; private float suckradius;
public MonsterHoarderBlockEntity(BlockPos pos, BlockState state) { public MonsterHoarderBlockEntity(BlockPos pos, BlockState state) {
super(QuickieFabricBlockEntity.MONSTERHOARDER, pos, state); super(QuickieFabricBlockEntity.MONSTERHOARDER, pos, state);
setSuckradius(8f); // TODO: make it level up - able and start with 2 setSuckradius(8f); // TODO: make it level up - able and start with 2
} }
public static void tick(World world, BlockPos pos, BlockState state, MonsterHoarderBlockEntity be) { public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
Box box = new Box(pos).expand(be.getSuckradius()); if (be instanceof MonsterHoarderBlockEntity) {
List<Entity> entities = world.getOtherEntities(null, box); MonsterHoarderBlockEntity mhbe = (MonsterHoarderBlockEntity) be;
for (Entity entity : entities) { Box box = new Box(pos).expand(mhbe.getSuckradius());
if (entity instanceof HostileEntity) { List<Entity> entities = world.getOtherEntities(null, box);
HostileEntity mobEntity = (HostileEntity) entity; for (Entity entity : entities) {
mobEntity.setOnFireFor(90); if (entity instanceof HostileEntity) {
HostileEntity mobEntity = (HostileEntity) entity;
mobEntity.setOnFireFor(90);
}
} }
} }
} }

View File

@ -44,9 +44,9 @@ public class BlockMonsterhoarder extends Block implements BlockEntityProvider {
@Override @Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type){ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type){
return checkType(type, QuickieBlocks.MONSTERHOARDER, (world1, pos, state1, be) -> MonsterHoarderBlockEntity.tick(world1, pos, state1, be)); return (world1, pos, state1, be) -> MonsterHoarderBlockEntity.tick(world1, pos, state1, be);
} }
@Override @Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) { public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>(); List<ItemStack> list = new ArrayList<>();

View File

@ -160,7 +160,7 @@ public class RegistryManager {
public static final <T extends BlockEntity> BlockEntityType<? extends T> registerBlockEntity(String name, public static final <T extends BlockEntity> BlockEntityType<? extends T> registerBlockEntity(String name,
FabricBlockEntityTypeBuilder.Factory<? extends T> supplier, Block... blocks) { FabricBlockEntityTypeBuilder.Factory<? extends T> supplier, Block... blocks) {
String fullname = new StringBuilder().append(QUICKIEFABRIC).append(":").append(name).toString(); String fullname = new StringBuilder().append(QUICKIEFABRIC).append(":").append(name).toString();
Builder<? extends T> builder = FabricBlockEntityTypeBuilder.create(supplier, blocks); FabricBlockEntityTypeBuilder<? extends T> builder = FabricBlockEntityTypeBuilder.create(supplier, blocks);
BlockEntityType<? extends T> blockEntityType = builder.build(null); BlockEntityType<? extends T> blockEntityType = builder.build(null);
return Registry.register(Registry.BLOCK_ENTITY_TYPE, fullname, blockEntityType); return Registry.register(Registry.BLOCK_ENTITY_TYPE, fullname, blockEntityType);
} }