Blocks (update 1 of 20)
This commit is contained in:
parent
b74fce581c
commit
81dd12c48c
13 changed files with 86 additions and 84 deletions
|
@ -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);
|
||||
|
|
|
@ -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<DetachedRiftBlockEntity> {
|
||||
public class DetachedRiftBlock extends BlockWithEntity implements RiftProvider<DetachedRiftBlockEntity> {
|
||||
public static final String ID = "rift";
|
||||
|
||||
public DetachedRiftBlock(Block.Settings settings) {
|
||||
|
@ -32,13 +34,8 @@ public class DetachedRiftBlock extends Block implements RiftProvider<DetachedRif
|
|||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockView blockView) {
|
||||
return new DetachedRiftBlockEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialColor getDefaultMaterialColor() {
|
||||
return MaterialColor.BLACK;
|
||||
public MapColor getDefaultMapColor() {
|
||||
return MapColor.BLACK;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -91,4 +88,16 @@ public class DetachedRiftBlock extends Block implements RiftProvider<DetachedRif
|
|||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
return VoxelShapes.fullCube();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new DetachedRiftBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
|
||||
return checkType(type, ModBlockEntityTypes.DETACHED_RIFT, DetachedRiftBlockEntity::tick);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<EntranceRiftBlockEntity>, ConditionalBlockEntityProvider {
|
||||
public class DimensionalDoorBlock extends DoorBlock implements RiftProvider<EntranceRiftBlockEntity> {
|
||||
public DimensionalDoorBlock(Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
@ -55,14 +55,13 @@ public class DimensionalDoorBlock extends DoorBlock implements RiftProvider<Entr
|
|||
return super.canReplace(state, context) || state.getBlock() == ModBlocks.DETACHED_RIFT;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockView world) {
|
||||
return new EntranceRiftBlockEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBlockEntity(BlockState blockState) {
|
||||
return blockState.get(DoorBlock.HALF) == DoubleBlockHalf.LOWER;
|
||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||
if (state.get(DoorBlock.HALF) == DoubleBlockHalf.LOWER) {
|
||||
return null;
|
||||
}
|
||||
return new EntranceRiftBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
package org.dimdev.dimdoors.block;
|
||||
|
||||
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
|
||||
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
|
||||
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
|
||||
import org.dimdev.dimdoors.util.TeleportUtil;
|
||||
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.DoorBlock;
|
||||
import net.minecraft.block.HorizontalFacingBlock;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.enums.DoubleBlockHalf;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
|
@ -37,9 +33,10 @@ public class DimensionalPortalBlock extends Block implements RiftProvider<Entran
|
|||
return (EntranceRiftBlockEntity) world.getBlockEntity(pos);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockView world) {
|
||||
return new EntranceRiftBlockEntity();
|
||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new EntranceRiftBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.dimdev.dimdoors.block;
|
||||
|
||||
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -18,7 +19,6 @@ import net.minecraft.util.shape.VoxelShapes;
|
|||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
// TODO: Make this placeable on rifts
|
||||
public class DimensionalTrapdoorBlock extends TrapdoorBlock implements RiftProvider<EntranceRiftBlockEntity> {
|
||||
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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<DetachedRiftBlockEntity> 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 <E extends BlockEntity> BlockEntityType<E> register(String id, Supplier<E> supplier, Block... blocks) {
|
||||
return Registry.register(Registry.BLOCK_ENTITY_TYPE, id, BlockEntityType.Builder.create(supplier, blocks).build(null));
|
||||
private static <E extends BlockEntity> BlockEntityType<E> register(String id, FabricBlockEntityTypeBuilder.Factory<E> 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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<? extends RiftBlockEntity> type) {
|
||||
super(type);
|
||||
public RiftBlockEntity(BlockEntityType<? extends RiftBlockEntity> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,17 +21,13 @@ import net.fabricmc.api.EnvType;
|
|||
import net.fabricmc.api.Environment;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class DetachedRiftBlockEntityRenderer extends BlockEntityRenderer<DetachedRiftBlockEntity> {
|
||||
public class DetachedRiftBlockEntityRenderer implements BlockEntityRenderer<DetachedRiftBlockEntity> {
|
||||
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) {
|
||||
|
|
|
@ -13,13 +13,7 @@ import net.fabricmc.api.EnvType;
|
|||
import net.fabricmc.api.Environment;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class EntranceRiftBlockEntityRenderer extends BlockEntityRenderer<EntranceRiftBlockEntity> {
|
||||
private static final Random RANDOM = new Random(31100L);
|
||||
|
||||
public EntranceRiftBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher) {
|
||||
super(blockEntityRenderDispatcher);
|
||||
}
|
||||
|
||||
public class EntranceRiftBlockEntityRenderer implements BlockEntityRenderer<EntranceRiftBlockEntity> {
|
||||
@Override
|
||||
public void render(EntranceRiftBlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
|
||||
DimensionalPortalRenderer.renderWithTransforms(
|
||||
|
|
Loading…
Reference in a new issue