From 81dd12c48c16331c5a57b921a6eacdda0633c463 Mon Sep 17 00:00:00 2001 From: SD Date: Thu, 11 Feb 2021 21:39:07 +0530 Subject: [PATCH] Blocks (update 1 of 20) --- .../dimdoors/DimensionalDoorsInitializer.java | 4 -- .../dimdoors/block/DetachedRiftBlock.java | 33 ++++++++----- .../dimdoors/block/DimensionalDoorBlock.java | 17 ++++--- .../block/DimensionalPortalBlock.java | 11 ++--- .../block/DimensionalTrapdoorBlock.java | 7 +-- .../dimdev/dimdoors/block/FabricBlock.java | 3 +- .../dimdoors/block/MarkingPlateBlock.java | 1 + .../block/entity/DetachedRiftBlockEntity.java | 47 +++++++++++-------- .../block/entity/EntranceRiftBlockEntity.java | 9 ++-- .../block/entity/ModBlockEntityTypes.java | 12 ++--- .../block/entity/RiftBlockEntity.java | 12 ++--- .../DetachedRiftBlockEntityRenderer.java | 6 +-- .../EntranceRiftBlockEntityRenderer.java | 8 +--- 13 files changed, 86 insertions(+), 84 deletions(-) diff --git a/src/main/java/org/dimdev/dimdoors/DimensionalDoorsInitializer.java b/src/main/java/org/dimdev/dimdoors/DimensionalDoorsInitializer.java index 260c17a2..634a699b 100644 --- a/src/main/java/org/dimdev/dimdoors/DimensionalDoorsInitializer.java +++ b/src/main/java/org/dimdev/dimdoors/DimensionalDoorsInitializer.java @@ -82,17 +82,13 @@ public class DimensionalDoorsInitializer implements ModInitializer { Targets.registerDefaultTargets(); VirtualTarget.VirtualTargetType.register(); - VirtualSingularPocket.VirtualSingularPocketType.register(); - Modifier.ModifierType.register(); - PocketGenerator.PocketGeneratorType.register(); SchematicV2Handler.getInstance().load(); SchematicHandler.INSTANCE.loadSchematics(); - AttackBlockCallback.EVENT.register(RiftConfigurationToolItem::onAttackBlockCallback); ServerPlayNetworking.registerGlobalReceiver(HitBlockS2CPacket.ID, RiftConfigurationToolItem::receiveHitBlock); diff --git a/src/main/java/org/dimdev/dimdoors/block/DetachedRiftBlock.java b/src/main/java/org/dimdev/dimdoors/block/DetachedRiftBlock.java index 0764a6d7..d31ad367 100644 --- a/src/main/java/org/dimdev/dimdoors/block/DetachedRiftBlock.java +++ b/src/main/java/org/dimdev/dimdoors/block/DetachedRiftBlock.java @@ -3,18 +3,20 @@ package org.dimdev.dimdoors.block; import java.util.Random; import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity; -import org.dimdev.dimdoors.particle.client.RiftParticle; +import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes; import org.dimdev.dimdoors.particle.client.RiftParticleEffect; import org.dimdev.dimdoors.world.ModDimensions; +import org.jetbrains.annotations.Nullable; import net.minecraft.block.Block; import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockState; -import net.minecraft.block.MaterialColor; +import net.minecraft.block.BlockWithEntity; +import net.minecraft.block.MapColor; import net.minecraft.block.ShapeContext; import net.minecraft.block.entity.BlockEntity; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.world.ClientWorld; +import net.minecraft.block.entity.BlockEntityTicker; +import net.minecraft.block.entity.BlockEntityType; import net.minecraft.util.math.BlockPos; import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShapes; @@ -24,7 +26,7 @@ import net.minecraft.world.World; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -public class DetachedRiftBlock extends Block implements RiftProvider { +public class DetachedRiftBlock extends BlockWithEntity implements RiftProvider { public static final String ID = "rift"; public DetachedRiftBlock(Block.Settings settings) { @@ -32,13 +34,8 @@ public class DetachedRiftBlock extends Block implements RiftProvider BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { + return checkType(type, ModBlockEntityTypes.DETACHED_RIFT, DetachedRiftBlockEntity::tick); + } } diff --git a/src/main/java/org/dimdev/dimdoors/block/DimensionalDoorBlock.java b/src/main/java/org/dimdev/dimdoors/block/DimensionalDoorBlock.java index 0c8f1c66..4012f97e 100644 --- a/src/main/java/org/dimdev/dimdoors/block/DimensionalDoorBlock.java +++ b/src/main/java/org/dimdev/dimdoors/block/DimensionalDoorBlock.java @@ -1,8 +1,8 @@ package org.dimdev.dimdoors.block; -import io.github.boogiemonster1o1.libcbe.api.ConditionalBlockEntityProvider; import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity; import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity; +import org.jetbrains.annotations.Nullable; import net.minecraft.block.BlockState; import net.minecraft.block.DoorBlock; @@ -22,7 +22,7 @@ import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.BlockView; import net.minecraft.world.World; -public class DimensionalDoorBlock extends DoorBlock implements RiftProvider, ConditionalBlockEntityProvider { +public class DimensionalDoorBlock extends DoorBlock implements RiftProvider { public DimensionalDoorBlock(Settings settings) { super(settings); } @@ -55,14 +55,13 @@ public class DimensionalDoorBlock extends DoorBlock implements RiftProvider { public DimensionalTrapdoorBlock(Block.Settings settings) { @@ -33,9 +33,10 @@ public class DimensionalTrapdoorBlock extends TrapdoorBlock implements RiftProvi } } + @Nullable @Override - public BlockEntity createBlockEntity(BlockView blockView) { - return new EntranceRiftBlockEntity(); + public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return new EntranceRiftBlockEntity(pos, state); } @Override diff --git a/src/main/java/org/dimdev/dimdoors/block/FabricBlock.java b/src/main/java/org/dimdev/dimdoors/block/FabricBlock.java index 2d9da4db..b5de821e 100644 --- a/src/main/java/org/dimdev/dimdoors/block/FabricBlock.java +++ b/src/main/java/org/dimdev/dimdoors/block/FabricBlock.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Map; import net.minecraft.block.Block; +import net.minecraft.block.BlockEntityProvider; import net.minecraft.block.BlockState; import net.minecraft.block.Material; import net.minecraft.entity.player.PlayerEntity; @@ -34,7 +35,7 @@ public class FabricBlock extends Block { if (world.canPlayerModifyAt(player, pos) && player.canPlaceOn(pos, hit.getSide(), heldStack) && heldBlock.getDefaultState().isFullCube(world, pos) && - !heldBlock.hasBlockEntity() && + !(heldBlock instanceof BlockEntityProvider) && heldBlock != this && !player.isSneaking() && !(heldBlock instanceof FabricBlock) diff --git a/src/main/java/org/dimdev/dimdoors/block/MarkingPlateBlock.java b/src/main/java/org/dimdev/dimdoors/block/MarkingPlateBlock.java index 454dbf24..c70c57ac 100644 --- a/src/main/java/org/dimdev/dimdoors/block/MarkingPlateBlock.java +++ b/src/main/java/org/dimdev/dimdoors/block/MarkingPlateBlock.java @@ -2,6 +2,7 @@ package org.dimdev.dimdoors.block; import net.minecraft.block.Block; +// TODO public class MarkingPlateBlock extends Block { public MarkingPlateBlock(Settings settings) { super(settings); diff --git a/src/main/java/org/dimdev/dimdoors/block/entity/DetachedRiftBlockEntity.java b/src/main/java/org/dimdev/dimdoors/block/entity/DetachedRiftBlockEntity.java index b1519326..7be9f759 100644 --- a/src/main/java/org/dimdev/dimdoors/block/entity/DetachedRiftBlockEntity.java +++ b/src/main/java/org/dimdev/dimdoors/block/entity/DetachedRiftBlockEntity.java @@ -6,18 +6,20 @@ import org.dimdev.dimdoors.DimensionalDoorsInitializer; import org.dimdev.dimdoors.block.ModBlocks; import org.dimdev.dimdoors.util.TeleportUtil; +import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.SpawnReason; import net.minecraft.entity.mob.EndermanEntity; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.Tickable; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -public class DetachedRiftBlockEntity extends RiftBlockEntity implements Tickable { +public class DetachedRiftBlockEntity extends RiftBlockEntity { private static final Random random = new Random(); public boolean closing = false; @@ -30,40 +32,47 @@ public class DetachedRiftBlockEntity extends RiftBlockEntity implements Tickable @Environment(EnvType.CLIENT) public double renderAngle; - public DetachedRiftBlockEntity() { - super(ModBlockEntityTypes.DETACHED_RIFT); + public DetachedRiftBlockEntity(BlockPos pos, BlockState state) { + super(ModBlockEntityTypes.DETACHED_RIFT, pos, state); } - @Override - public void tick() { - if (this.world == null) { -// DynamicRegistryManager + public static void tick(World world, BlockPos pos, BlockState state, DetachedRiftBlockEntity blockEntity) { + if (world == null) { return; } - if (this.world.getBlockState(this.pos).getBlock() != ModBlocks.DETACHED_RIFT) { - this.markInvalid(); + if (state.getBlock() != ModBlocks.DETACHED_RIFT) { + blockEntity.markRemoved(); return; } - if (!this.world.isClient() && random.nextDouble() < DimensionalDoorsInitializer.CONFIG.getGeneralConfig().endermanSpawnChance) { - EndermanEntity enderman = EntityType.ENDERMAN.spawn((ServerWorld) this.world, null, null, null, this.pos, SpawnReason.STRUCTURE, false, false); + if (!world.isClient() && random.nextDouble() < DimensionalDoorsInitializer.CONFIG.getGeneralConfig().endermanSpawnChance) { + EndermanEntity enderman = EntityType.ENDERMAN.spawn( + (ServerWorld) world, + null, + null, + null, + pos, + SpawnReason.STRUCTURE, + false, + false + ); if (random.nextDouble() < DimensionalDoorsInitializer.CONFIG.getGeneralConfig().endermanAggressiveChance) { if (enderman != null) { - enderman.setTarget(this.world.getClosestPlayer(enderman, 50)); + enderman.setTarget(world.getClosestPlayer(enderman, 50)); } } } - if (this.closing) { - if (this.size > 0) { - this.size -= DimensionalDoorsInitializer.CONFIG.getGeneralConfig().riftCloseSpeed; + if (blockEntity.closing) { + if (blockEntity.size > 0) { + blockEntity.size -= DimensionalDoorsInitializer.CONFIG.getGeneralConfig().riftCloseSpeed; } else { - this.world.removeBlock(this.pos, false); + world.removeBlock(pos, false); } - } else if (!this.stabilized) { - this.size += DimensionalDoorsInitializer.CONFIG.getGeneralConfig().riftGrowthSpeed / (this.size + 1); + } else if (!blockEntity.stabilized) { + blockEntity.size += DimensionalDoorsInitializer.CONFIG.getGeneralConfig().riftGrowthSpeed / (blockEntity.size + 1); } } diff --git a/src/main/java/org/dimdev/dimdoors/block/entity/EntranceRiftBlockEntity.java b/src/main/java/org/dimdev/dimdoors/block/entity/EntranceRiftBlockEntity.java index b55ee624..37bc6111 100644 --- a/src/main/java/org/dimdev/dimdoors/block/entity/EntranceRiftBlockEntity.java +++ b/src/main/java/org/dimdev/dimdoors/block/entity/EntranceRiftBlockEntity.java @@ -10,17 +10,18 @@ import net.minecraft.block.DoorBlock; import net.minecraft.block.HorizontalFacingBlock; import net.minecraft.entity.Entity; import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; public class EntranceRiftBlockEntity extends RiftBlockEntity { - public EntranceRiftBlockEntity() { - super(ModBlockEntityTypes.ENTRANCE_RIFT); + public EntranceRiftBlockEntity(BlockPos pos, BlockState state) { + super(ModBlockEntityTypes.ENTRANCE_RIFT, pos, state); } @Override - public void fromTag(BlockState state, CompoundTag nbt) { - super.fromTag(state, nbt); + public void fromTag(CompoundTag nbt) { + super.fromTag(nbt); } @Override diff --git a/src/main/java/org/dimdev/dimdoors/block/entity/ModBlockEntityTypes.java b/src/main/java/org/dimdev/dimdoors/block/entity/ModBlockEntityTypes.java index 281b5d31..033d9c92 100644 --- a/src/main/java/org/dimdev/dimdoors/block/entity/ModBlockEntityTypes.java +++ b/src/main/java/org/dimdev/dimdoors/block/entity/ModBlockEntityTypes.java @@ -1,8 +1,5 @@ package org.dimdev.dimdoors.block.entity; -import java.util.function.Supplier; - -import com.google.common.collect.Sets; import org.dimdev.dimdoors.block.ModBlocks; import org.dimdev.dimdoors.client.DetachedRiftBlockEntityRenderer; import org.dimdev.dimdoors.client.EntranceRiftBlockEntityRenderer; @@ -15,6 +12,7 @@ import net.minecraft.util.registry.Registry; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry; +import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; public class ModBlockEntityTypes { public static final BlockEntityType DETACHED_RIFT = register( @@ -27,8 +25,8 @@ public class ModBlockEntityTypes { EntranceRiftBlockEntity::new, ModBlocks.OAK_DIMENSIONAL_DOOR, ModBlocks.IRON_DIMENSIONAL_DOOR, ModBlocks.GOLD_DIMENSIONAL_DOOR, ModBlocks.QUARTZ_DIMENSIONAL_DOOR, ModBlocks.DIMENSIONAL_PORTAL); - private static BlockEntityType register(String id, Supplier supplier, Block... blocks) { - return Registry.register(Registry.BLOCK_ENTITY_TYPE, id, BlockEntityType.Builder.create(supplier, blocks).build(null)); + private static BlockEntityType register(String id, FabricBlockEntityTypeBuilder.Factory factory, Block... blocks) { + return Registry.register(Registry.BLOCK_ENTITY_TYPE, id, FabricBlockEntityTypeBuilder.create(factory, blocks).build()); } public static void init() { @@ -37,7 +35,7 @@ public class ModBlockEntityTypes { @Environment(EnvType.CLIENT) public static void initClient() { - BlockEntityRendererRegistry.INSTANCE.register(ModBlockEntityTypes.ENTRANCE_RIFT, EntranceRiftBlockEntityRenderer::new); - BlockEntityRendererRegistry.INSTANCE.register(ModBlockEntityTypes.DETACHED_RIFT, DetachedRiftBlockEntityRenderer::new); + BlockEntityRendererRegistry.INSTANCE.register(ModBlockEntityTypes.ENTRANCE_RIFT, ctx -> new EntranceRiftBlockEntityRenderer()); + BlockEntityRendererRegistry.INSTANCE.register(ModBlockEntityTypes.DETACHED_RIFT, ctx -> new DetachedRiftBlockEntityRenderer()); } } diff --git a/src/main/java/org/dimdev/dimdoors/block/entity/RiftBlockEntity.java b/src/main/java/org/dimdev/dimdoors/block/entity/RiftBlockEntity.java index 677f5eea..38ee871a 100644 --- a/src/main/java/org/dimdev/dimdoors/block/entity/RiftBlockEntity.java +++ b/src/main/java/org/dimdev/dimdoors/block/entity/RiftBlockEntity.java @@ -26,6 +26,7 @@ import net.minecraft.entity.Entity; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.world.ServerWorld; import net.minecraft.text.LiteralText; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable; @@ -37,16 +38,15 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity @NotNull protected RiftData data = new RiftData(); - protected boolean riftStateChanged; // not saved + protected boolean riftStateChanged; - public RiftBlockEntity(BlockEntityType type) { - super(type); + public RiftBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { + super(type, pos, state); } - // NBT @Override - public void fromTag(BlockState state, CompoundTag nbt) { - super.fromTag(state, nbt); + public void fromTag(CompoundTag nbt) { + super.fromTag(nbt); this.deserialize(nbt); } diff --git a/src/main/java/org/dimdev/dimdoors/client/DetachedRiftBlockEntityRenderer.java b/src/main/java/org/dimdev/dimdoors/client/DetachedRiftBlockEntityRenderer.java index d87f35f7..0a9e3ce2 100644 --- a/src/main/java/org/dimdev/dimdoors/client/DetachedRiftBlockEntityRenderer.java +++ b/src/main/java/org/dimdev/dimdoors/client/DetachedRiftBlockEntityRenderer.java @@ -21,17 +21,13 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @Environment(EnvType.CLIENT) -public class DetachedRiftBlockEntityRenderer extends BlockEntityRenderer { +public class DetachedRiftBlockEntityRenderer implements BlockEntityRenderer { public static final Identifier TESSERACT_PATH = new Identifier("dimdoors:textures/other/tesseract.png"); private final RGBA color = new RGBA(1, 0.5f, 1, 1); private static final Tesseract TESSERACT = new Tesseract(); private static final RiftCurves.PolygonInfo CURVE = RiftCurves.CURVES.get(0); - public DetachedRiftBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) { - super(dispatcher); - } - @Override public void render(DetachedRiftBlockEntity rift, float tickDelta, MatrixStack matrices, VertexConsumerProvider vcs, int breakProgress, int alpha) { if (DimensionalDoorsInitializer.CONFIG.getGraphicsConfig().showRiftCore) { diff --git a/src/main/java/org/dimdev/dimdoors/client/EntranceRiftBlockEntityRenderer.java b/src/main/java/org/dimdev/dimdoors/client/EntranceRiftBlockEntityRenderer.java index d3ec5ea9..990ff3af 100644 --- a/src/main/java/org/dimdev/dimdoors/client/EntranceRiftBlockEntityRenderer.java +++ b/src/main/java/org/dimdev/dimdoors/client/EntranceRiftBlockEntityRenderer.java @@ -13,13 +13,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @Environment(EnvType.CLIENT) -public class EntranceRiftBlockEntityRenderer extends BlockEntityRenderer { - private static final Random RANDOM = new Random(31100L); - - public EntranceRiftBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher) { - super(blockEntityRenderDispatcher); - } - +public class EntranceRiftBlockEntityRenderer implements BlockEntityRenderer { @Override public void render(EntranceRiftBlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { DimensionalPortalRenderer.renderWithTransforms(