Partial pedestals fix

This commit is contained in:
paulevsGitch 2021-12-28 21:50:15 +03:00
parent 87c37f1cef
commit 1ae6d0d63e
5 changed files with 68 additions and 120 deletions

View file

@ -1,12 +1,12 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import com.google.common.collect.Maps;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.blocks.basis.PedestalBlock; import ru.betterend.blocks.basis.PedestalBlock;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class EndPedestal extends PedestalBlock { public class EndPedestal extends PedestalBlock {
@ -19,16 +19,12 @@ public class EndPedestal extends PedestalBlock {
protected Map<String, String> createTexturesMap() { protected Map<String, String> createTexturesMap() {
ResourceLocation blockId = Registry.BLOCK.getKey(parent); ResourceLocation blockId = Registry.BLOCK.getKey(parent);
String name = blockId.getPath(); String name = blockId.getPath();
return new HashMap<String, String>() { Map<String, String> textures = Maps.newHashMap();
private static final long serialVersionUID = 1L; textures.put("%mod%", BetterEnd.MOD_ID);
textures.put("%top%", name + "_polished");
{ textures.put("%base%", name + "_polished");
put("%mod%", BetterEnd.MOD_ID); textures.put("%pillar%", name + "_pillar_side");
put("%top%", name + "_polished"); textures.put("%bottom%", name + "_polished");
put("%base%", name + "_polished"); return textures;
put("%pillar%", name + "_pillar_side");
put("%bottom%", name + "_polished");
}
};
} }
} }

View file

@ -1,6 +1,7 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -23,8 +24,6 @@ import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.BooleanProperty;
@ -45,17 +44,14 @@ import ru.betterend.blocks.InfusionPedestal;
import ru.betterend.blocks.entities.InfusionPedestalEntity; import ru.betterend.blocks.entities.InfusionPedestalEntity;
import ru.betterend.blocks.entities.PedestalBlockEntity; import ru.betterend.blocks.entities.PedestalBlockEntity;
import ru.betterend.client.models.Patterns; import ru.betterend.client.models.Patterns;
import ru.betterend.registry.EndBlocks;
import ru.betterend.rituals.InfusionRitual; import ru.betterend.rituals.InfusionRitual;
import java.awt.Point; import java.awt.Point;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.function.ToIntFunction; import java.util.function.ToIntFunction;
@SuppressWarnings({"deprecation"})
public class PedestalBlock extends BaseBlockNotFull implements EntityBlock { public class PedestalBlock extends BaseBlockNotFull implements EntityBlock {
public final static EnumProperty<PedestalState> STATE = EndBlockProperties.PEDESTAL_STATE; public final static EnumProperty<PedestalState> STATE = EndBlockProperties.PEDESTAL_STATE;
public static final BooleanProperty HAS_ITEM = EndBlockProperties.HAS_ITEM; public static final BooleanProperty HAS_ITEM = EndBlockProperties.HAS_ITEM;
@ -68,37 +64,18 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock {
private static final VoxelShape SHAPE_COLUMN_TOP; private static final VoxelShape SHAPE_COLUMN_TOP;
private static final VoxelShape SHAPE_BOTTOM; private static final VoxelShape SHAPE_BOTTOM;
/**
* Register new Pedestal block with Better End mod id.
*
* @param name pedestal name
* @param source source block
* @return new Pedestal block with Better End id.
*/
public static Block registerPedestal(String name, Block source) {
return EndBlocks.registerBlock(name, new PedestalBlock(source));
}
/**
* Register new Pedestal block with specified mod id.
*
* @param id pedestal id
* @param source source block
* @return new Pedestal block with specified id.
*/
public static Block registerPedestal(ResourceLocation id, Block source) {
return EndBlocks.registerBlock(id, new PedestalBlock(source));
}
protected final Block parent; protected final Block parent;
protected float height = 1.0F; protected float height = 1.0F;
public PedestalBlock(Block parent) { public PedestalBlock(Block parent) {
super(FabricBlockSettings.copyOf(parent).luminance(getLuminance(parent.defaultBlockState()))); super(FabricBlockSettings.copyOf(parent).luminance(getLuminance(parent.defaultBlockState())));
this.registerDefaultState(stateDefinition.any() this.registerDefaultState(
stateDefinition
.any()
.setValue(STATE, PedestalState.DEFAULT) .setValue(STATE, PedestalState.DEFAULT)
.setValue(HAS_ITEM, false) .setValue(HAS_ITEM, false)
.setValue(HAS_LIGHT, false)); .setValue(HAS_LIGHT, false)
);
this.parent = parent; this.parent = parent;
} }
@ -118,28 +95,29 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock {
} }
@Override @Override
@Deprecated @SuppressWarnings("deprecation")
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (world.isClientSide || !state.is(this)) return InteractionResult.CONSUME; if (!state.is(this) || !isPlaceable(state)) {
if (!isPlaceable(state)) {
return InteractionResult.PASS; return InteractionResult.PASS;
} }
BlockEntity blockEntity = world.getBlockEntity(pos); BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity instanceof PedestalBlockEntity) { if (blockEntity instanceof PedestalBlockEntity) {
PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity; PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity;
if (pedestal.isEmpty()) { if (pedestal.isEmpty()) {
ItemStack itemStack = player.getItemInHand(hand); ItemStack itemStack = player.getItemInHand(hand);
if (itemStack.isEmpty()) return InteractionResult.CONSUME; if (itemStack.isEmpty()) return InteractionResult.CONSUME;
pedestal.setItem(0, itemStack); pedestal.setItem(0, itemStack);
checkRitual(world, pos); level.blockEntityChanged(pos);
return InteractionResult.SUCCESS; checkRitual(level, pos);
return InteractionResult.SUCCESS;//InteractionResult.sidedSuccess(level.isClientSide());
} }
else { else {
ItemStack itemStack = pedestal.getItem(0); ItemStack itemStack = pedestal.getItem(0);
if (player.addItem(itemStack)) { if (player.addItem(itemStack)) {
pedestal.removeItemNoUpdate(0); pedestal.removeItemNoUpdate(0);
checkRitual(world, pos); level.blockEntityChanged(pos);
return InteractionResult.SUCCESS; checkRitual(level, pos);
return InteractionResult.SUCCESS;//InteractionResult.sidedSuccess(level.isClientSide());
} }
return InteractionResult.FAIL; return InteractionResult.FAIL;
} }
@ -207,7 +185,7 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock {
} }
@Override @Override
@Deprecated @SuppressWarnings("deprecation")
public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) { public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) {
BlockState updated = getUpdatedState(state, direction, newState, world, pos, posFrom); BlockState updated = getUpdatedState(state, direction, newState, world, pos, posFrom);
if (!updated.is(this)) return updated; if (!updated.is(this)) return updated;
@ -344,7 +322,7 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock {
} }
@Override @Override
@Deprecated @SuppressWarnings("deprecation")
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
if (state.is(this)) { if (state.is(this)) {
switch (state.getValue(STATE)) { switch (state.getValue(STATE)) {
@ -386,13 +364,13 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock {
} }
@Override @Override
@Deprecated @SuppressWarnings("deprecation")
public boolean hasAnalogOutputSignal(BlockState state) { public boolean hasAnalogOutputSignal(BlockState state) {
return state.getBlock() instanceof PedestalBlock; return state.getBlock() instanceof PedestalBlock;
} }
@Override @Override
@Deprecated @SuppressWarnings("deprecation")
public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) { public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) {
return state.getValue(HAS_ITEM) ? 15 : 0; return state.getValue(HAS_ITEM) ? 15 : 0;
} }
@ -446,17 +424,13 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock {
protected Map<String, String> createTexturesMap() { protected Map<String, String> createTexturesMap() {
ResourceLocation blockId = Registry.BLOCK.getKey(parent); ResourceLocation blockId = Registry.BLOCK.getKey(parent);
String name = blockId.getPath(); String name = blockId.getPath();
return new HashMap<String, String>() { Map<String, String> textures = Maps.newHashMap();
private static final long serialVersionUID = 1L; textures.put("%mod%", blockId.getNamespace());
textures.put("%top%", name + "_top");
{ textures.put("%base%", name + "_base");
put("%mod%", blockId.getNamespace()); textures.put("%pillar%", name + "_pillar");
put("%top%", name + "_top"); textures.put("%bottom%", name + "_bottom");
put("%base%", name + "_base"); return textures;
put("%pillar%", name + "_pillar");
put("%bottom%", name + "_bottom");
}
};
} }
static { static {
@ -478,9 +452,9 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock {
SHAPE_BOTTOM = Shapes.or(basin, SHAPE_PILLAR); SHAPE_BOTTOM = Shapes.or(basin, SHAPE_PILLAR);
} }
@Override /*@Override
@Nullable @Nullable
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> blockEntityType) { public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> blockEntityType) {
return level.isClientSide() ? PedestalBlockEntity::tick : null; return level.isClientSide() ? PedestalBlockEntity::tick : null;
} }*/
} }

View file

@ -62,7 +62,7 @@ public class InfusionPedestalEntity extends PedestalBlockEntity {
if (blockEntity.hasRitual()) { if (blockEntity.hasRitual()) {
blockEntity.linkedRitual.tick(); blockEntity.linkedRitual.tick();
} }
PedestalBlockEntity.tick(level, blockPos, blockState, blockEntity); //PedestalBlockEntity.tick(level, blockPos, blockState, blockEntity);
} }
} }
} }

View file

@ -1,12 +1,13 @@
package ru.betterend.blocks.entities; package ru.betterend.blocks.entities;
//import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable; //import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.world.Container; import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
@ -18,8 +19,8 @@ import ru.betterend.registry.EndItems;
public class PedestalBlockEntity extends BlockEntity implements Container/*, BlockEntityClientSerializable*/ { public class PedestalBlockEntity extends BlockEntity implements Container/*, BlockEntityClientSerializable*/ {
private ItemStack activeItem = ItemStack.EMPTY; private ItemStack activeItem = ItemStack.EMPTY;
private final int maxAge = 314; //private final int maxAge = 314;
private int age; //private int age;
public PedestalBlockEntity(BlockPos blockPos, BlockState blockState) { public PedestalBlockEntity(BlockPos blockPos, BlockState blockState) {
this(EndBlockEntities.PEDESTAL, blockPos, blockState); this(EndBlockEntities.PEDESTAL, blockPos, blockState);
@ -29,13 +30,13 @@ public class PedestalBlockEntity extends BlockEntity implements Container/*, Blo
super(blockEntityType, blockPos, blockState); super(blockEntityType, blockPos, blockState);
} }
public int getAge() { /*public int getAge() {
return age; return age;
} }*/
public int getMaxAge() { /*public int getMaxAge() {
return maxAge; return maxAge;
} }*/
@Override @Override
public int getContainerSize() { public int getContainerSize() {
@ -99,7 +100,6 @@ public class PedestalBlockEntity extends BlockEntity implements Container/*, Blo
super.setChanged(); super.setChanged();
} }
@Override @Override
public boolean stillValid(Player player) { public boolean stillValid(Player player) {
return true; return true;
@ -111,22 +111,12 @@ public class PedestalBlockEntity extends BlockEntity implements Container/*, Blo
fromTag(tag); fromTag(tag);
} }
/*@Override
public CompoundTag save(CompoundTag tag) {
tag.put("active_item", activeItem.save(new CompoundTag()));
return super.save(tag);
}
@Override @Override
public void fromClientTag(CompoundTag tag) { protected void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
fromTag(tag); fromTag(tag);
} }
@Override
public CompoundTag toClientTag(CompoundTag tag) {
return save(tag);
}*/
protected void fromTag(CompoundTag tag) { protected void fromTag(CompoundTag tag) {
if (tag.contains("active_item")) { if (tag.contains("active_item")) {
CompoundTag itemTag = tag.getCompound("active_item"); CompoundTag itemTag = tag.getCompound("active_item");
@ -134,16 +124,26 @@ public class PedestalBlockEntity extends BlockEntity implements Container/*, Blo
} }
} }
public static <T extends BlockEntity> void tick(Level level, BlockPos blockPos, BlockState blockState, T uncastedEntity) { /*public static <T extends BlockEntity> void tick(Level level, BlockPos blockPos, BlockState blockState, T uncastedEntity) {
clientTick(level, blockPos, blockState, (PedestalBlockEntity) uncastedEntity); clientTick(level, blockPos, blockState, (PedestalBlockEntity) uncastedEntity);
} }*/
private static void clientTick(Level tickLevel, BlockPos tickPos, BlockState tickState, PedestalBlockEntity blockEntity) { /*private static void clientTick(Level tickLevel, BlockPos tickPos, BlockState tickState, PedestalBlockEntity blockEntity) {
if (!blockEntity.isEmpty()) { if (!blockEntity.isEmpty()) {
blockEntity.age++; blockEntity.age++;
if (blockEntity.age > blockEntity.maxAge) { if (blockEntity.age > blockEntity.maxAge) {
blockEntity.age = 0; blockEntity.age = 0;
} }
} }
}*/
@Override
public ClientboundBlockEntityDataPacket getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this);
}
@Override
public CompoundTag getUpdateTag() {
return this.saveWithoutMetadata();
} }
} }

View file

@ -24,7 +24,6 @@ import ru.betterend.registry.EndItems;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class PedestalItemRenderer<T extends PedestalBlockEntity> implements BlockEntityRenderer<T> { public class PedestalItemRenderer<T extends PedestalBlockEntity> implements BlockEntityRenderer<T> {
public PedestalItemRenderer(BlockEntityRendererProvider.Context ctx) { public PedestalItemRenderer(BlockEntityRendererProvider.Context ctx) {
super(); super();
} }
@ -41,7 +40,6 @@ public class PedestalItemRenderer<T extends PedestalBlockEntity> implements Bloc
matrices.pushPose(); matrices.pushPose();
Minecraft minecraft = Minecraft.getInstance(); Minecraft minecraft = Minecraft.getInstance();
//TODO: check i=0
BakedModel model = minecraft.getItemRenderer().getModel(activeItem, world, null, 0); BakedModel model = minecraft.getItemRenderer().getModel(activeItem, world, null, 0);
Vector3f translate = model.getTransforms().ground.translation; Vector3f translate = model.getTransforms().ground.translation;
PedestalBlock pedestal = (PedestalBlock) state.getBlock(); PedestalBlock pedestal = (PedestalBlock) state.getBlock();
@ -52,28 +50,17 @@ public class PedestalItemRenderer<T extends PedestalBlockEntity> implements Bloc
else { else {
matrices.scale(1.25F, 1.25F, 1.25F); matrices.scale(1.25F, 1.25F, 1.25F);
} }
int age = blockEntity.getAge(); int age = (int) (minecraft.level.getGameTime() % 314);
if (state.is(EndBlocks.ETERNAL_PEDESTAL) && state.getValue(EternalPedestal.ACTIVATED)) { if (state.is(EndBlocks.ETERNAL_PEDESTAL) && state.getValue(EternalPedestal.ACTIVATED)) {
float[] colors = EternalCrystalRenderer.colors(age); float[] colors = EternalCrystalRenderer.colors(age);
int y = blockEntity.getBlockPos().getY(); int y = blockEntity.getBlockPos().getY();
BeamRenderer.renderLightBeam( BeamRenderer.renderLightBeam(matrices, vertexConsumers, age, tickDelta, -y, 1024 - y, colors, 0.25F, 0.13F, 0.16F);
matrices, float altitude = Mth.sin((age + tickDelta) / 10.0F) * 0.1F + 0.1F;
vertexConsumers,
age,
tickDelta,
-y,
1024 - y,
colors,
0.25F,
0.13F,
0.16F
);
float altitude = Mth.sin((blockEntity.getAge() + tickDelta) / 10.0F) * 0.1F + 0.1F;
matrices.translate(0.0D, altitude, 0.0D); matrices.translate(0.0D, altitude, 0.0D);
} }
if (activeItem.getItem() == Items.END_CRYSTAL) { if (activeItem.getItem() == Items.END_CRYSTAL) {
EndCrystalRenderer.render(age, blockEntity.getMaxAge(), tickDelta, matrices, vertexConsumers, light); EndCrystalRenderer.render(age, 314, tickDelta, matrices, vertexConsumers, light);
} }
else if (activeItem.getItem() == EndItems.ETERNAL_CRYSTAL) { else if (activeItem.getItem() == EndItems.ETERNAL_CRYSTAL) {
EternalCrystalRenderer.render(age, tickDelta, matrices, vertexConsumers, light); EternalCrystalRenderer.render(age, tickDelta, matrices, vertexConsumers, light);
@ -81,16 +68,7 @@ public class PedestalItemRenderer<T extends PedestalBlockEntity> implements Bloc
else { else {
float rotation = (age + tickDelta) / 25.0F + 6.0F; float rotation = (age + tickDelta) / 25.0F + 6.0F;
matrices.mulPose(Vector3f.YP.rotation(rotation)); matrices.mulPose(Vector3f.YP.rotation(rotation));
minecraft.getItemRenderer() minecraft.getItemRenderer().render(activeItem, ItemTransforms.TransformType.GROUND, false, matrices, vertexConsumers, light, overlay, model);
.render(activeItem,
ItemTransforms.TransformType.GROUND,
false,
matrices,
vertexConsumers,
light,
overlay,
model
);
} }
matrices.popPose(); matrices.popPose();
} }