Items and Blocks registries (WIP)
This commit is contained in:
parent
41df84404b
commit
a3e781b401
34 changed files with 313 additions and 1771 deletions
|
@ -1,132 +1,10 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.resources.model.BlockModelRotation;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.monster.piglin.PiglinAi;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.BarrelBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import ru.betterend.blocks.entities.EBarrelBlockEntity;
|
||||
import ru.betterend.client.models.BlockModelProvider;
|
||||
import ru.betterend.client.models.ModelsHelper;
|
||||
import ru.betterend.client.models.Patterns;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
import ru.bclib.blocks.BaseBarrelBlock;
|
||||
|
||||
public class EndBarrelBlock extends BarrelBlock implements BlockModelProvider {
|
||||
public class EndBarrelBlock extends BaseBarrelBlock {
|
||||
public EndBarrelBlock(Block source) {
|
||||
super(FabricBlockSettings.copyOf(source).noOcclusion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockGetter world) {
|
||||
return EndBlockEntities.BARREL.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
||||
List<ItemStack> drop = super.getDrops(state, builder);
|
||||
drop.add(new ItemStack(this.asItem()));
|
||||
return drop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand,
|
||||
BlockHitResult hit) {
|
||||
if (world.isClientSide) {
|
||||
return InteractionResult.SUCCESS;
|
||||
} else {
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (blockEntity instanceof EBarrelBlockEntity) {
|
||||
player.openMenu((EBarrelBlockEntity) blockEntity);
|
||||
player.awardStat(Stats.OPEN_BARREL);
|
||||
PiglinAi.angerNearbyPiglins(player, true);
|
||||
}
|
||||
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (blockEntity instanceof EBarrelBlockEntity) {
|
||||
((EBarrelBlockEntity) blockEntity).tick();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RenderShape getRenderShape(BlockState state) {
|
||||
return RenderShape.MODEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer,
|
||||
ItemStack itemStack) {
|
||||
if (itemStack.hasCustomHoverName()) {
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (blockEntity instanceof EBarrelBlockEntity) {
|
||||
((EBarrelBlockEntity) blockEntity).setCustomName(itemStack.getHoverName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockModel getItemModel(ResourceLocation blockId) {
|
||||
return getBlockModel(blockId, defaultBlockState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||
String texture = blockId.getPath();
|
||||
Optional<String> pattern;
|
||||
if (blockState.getValue(OPEN)) {
|
||||
pattern = Patterns.createJson(Patterns.BLOCK_BARREL_OPEN, texture, texture);
|
||||
} else {
|
||||
pattern = Patterns.createJson(Patterns.BLOCK_BOTTOM_TOP, texture, texture);
|
||||
}
|
||||
return ModelsHelper.fromPattern(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||
String open = blockState.getValue(OPEN) ? "_open" : "";
|
||||
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + open);
|
||||
registerBlockModel(stateId, modelId, blockState, modelCache);
|
||||
Direction facing = blockState.getValue(FACING);
|
||||
BlockModelRotation rotation = BlockModelRotation.X0_Y0;
|
||||
switch (facing) {
|
||||
case NORTH: rotation = BlockModelRotation.X90_Y0; break;
|
||||
case EAST: rotation = BlockModelRotation.X90_Y90; break;
|
||||
case SOUTH: rotation = BlockModelRotation.X90_Y180; break;
|
||||
case WEST: rotation = BlockModelRotation.X90_Y270; break;
|
||||
case DOWN: rotation = BlockModelRotation.X180_Y0; break;
|
||||
default: break;
|
||||
}
|
||||
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
|
||||
super(source);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,42 +16,14 @@ import net.minecraft.world.level.block.ChestBlock;
|
|||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import ru.bclib.blocks.BaseChestBlock;
|
||||
import ru.betterend.client.models.BlockModelProvider;
|
||||
import ru.betterend.client.models.ModelsHelper;
|
||||
import ru.betterend.client.models.Patterns;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
|
||||
public class EndChestBlock extends ChestBlock implements BlockModelProvider {
|
||||
private final Block parent;
|
||||
|
||||
public class EndChestBlock extends BaseChestBlock {
|
||||
public EndChestBlock(Block source) {
|
||||
super(FabricBlockSettings.copyOf(source).noOcclusion(), () -> EndBlockEntities.CHEST);
|
||||
this.parent = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockGetter world)
|
||||
{
|
||||
return EndBlockEntities.CHEST.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder)
|
||||
{
|
||||
List<ItemStack> drop = super.getDrops(state, builder);
|
||||
drop.add(new ItemStack(this.asItem()));
|
||||
return drop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockModel getItemModel(ResourceLocation blockId) {
|
||||
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_CHEST, blockId.getPath());
|
||||
return ModelsHelper.fromPattern(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||
return ModelsHelper.createBlockEmpty(parentId);
|
||||
super(source);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,104 +1,10 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.FurnaceBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import ru.betterend.blocks.entities.EFurnaceBlockEntity;
|
||||
import ru.betterend.client.models.BlockModelProvider;
|
||||
import ru.betterend.client.models.ModelsHelper;
|
||||
import ru.betterend.client.models.Patterns;
|
||||
import ru.betterend.client.render.ERenderLayer;
|
||||
import ru.betterend.interfaces.IRenderTypeable;
|
||||
import ru.bclib.blocks.BaseFurnaceBlock;
|
||||
|
||||
public class EndFurnaceBlock extends FurnaceBlock implements BlockModelProvider, IRenderTypeable {
|
||||
public class EndFurnaceBlock extends BaseFurnaceBlock {
|
||||
public EndFurnaceBlock(Block source) {
|
||||
super(FabricBlockSettings.copyOf(source).luminance(state -> state.getValue(LIT) ? 13 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockGetter world) {
|
||||
return new EFurnaceBlockEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void openContainer(Level world, BlockPos pos, Player player) {
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (blockEntity instanceof EFurnaceBlockEntity) {
|
||||
player.openMenu((MenuProvider) blockEntity);
|
||||
player.awardStat(Stats.INTERACT_WITH_FURNACE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||
String blockName = blockId.getPath();
|
||||
Map<String, String> textures = Maps.newHashMap();
|
||||
textures.put("%top%", blockName + "_top");
|
||||
textures.put("%side%", blockName + "_side");
|
||||
Optional<String> pattern;
|
||||
if (blockState.getValue(LIT)) {
|
||||
textures.put("%front%", blockName + "_front_on");
|
||||
textures.put("%glow%", blockName + "_glow");
|
||||
pattern = Patterns.createJson(Patterns.BLOCK_FURNACE_LIT, textures);
|
||||
} else {
|
||||
textures.put("%front%", blockName + "_front");
|
||||
pattern = Patterns.createJson(Patterns.BLOCK_FURNACE, textures);
|
||||
}
|
||||
return ModelsHelper.fromPattern(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockModel getItemModel(ResourceLocation resourceLocation) {
|
||||
return getBlockModel(resourceLocation, defaultBlockState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||
String lit = blockState.getValue(LIT) ? "_lit" : "";
|
||||
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
|
||||
"block/" + stateId.getPath() + lit);
|
||||
registerBlockModel(stateId, modelId, blockState, modelCache);
|
||||
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING), false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ERenderLayer getRenderLayer() {
|
||||
return ERenderLayer.CUTOUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
||||
List<ItemStack> drop = Lists.newArrayList(new ItemStack(this));
|
||||
BlockEntity blockEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
|
||||
if (blockEntity instanceof EFurnaceBlockEntity) {
|
||||
EFurnaceBlockEntity entity = (EFurnaceBlockEntity) blockEntity;
|
||||
for (int i = 0; i < entity.getContainerSize(); i++) {
|
||||
drop.add(entity.getItem(i));
|
||||
}
|
||||
}
|
||||
return drop;
|
||||
super(source);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import ru.betterend.client.models.ModelsHelper;
|
||||
import ru.betterend.client.models.Patterns;
|
||||
|
||||
public class EndPathBlock extends BlockBaseNotFull {
|
||||
private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 15, 16);
|
||||
|
||||
public EndPathBlock(Block source) {
|
||||
super(FabricBlockSettings.copyOf(source).isValidSpawn((state, world, pos, type) -> { return false; }));
|
||||
if (source instanceof EndTerrainBlock) {
|
||||
EndTerrainBlock terrain = (EndTerrainBlock) source;
|
||||
terrain.setPathBlock(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
||||
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
|
||||
if (tool != null && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
|
||||
return Collections.singletonList(new ItemStack(this));
|
||||
}
|
||||
return Collections.singletonList(new ItemStack(Blocks.END_STONE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
|
||||
return SHAPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
|
||||
return SHAPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockModel getItemModel(ResourceLocation blockId) {
|
||||
return getBlockModel(blockId, defaultBlockState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
String name = resourceLocation.getPath();
|
||||
Map<String, String> textures = Maps.newHashMap();
|
||||
textures.put("%top%", name + "_top");
|
||||
textures.put("%side%", name.replace("_path", "") + "_side");
|
||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_PATH, textures);
|
||||
return ModelsHelper.fromPattern(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath());
|
||||
registerBlockModel(stateId, modelId, blockState, modelCache);
|
||||
return ModelsHelper.createRandomTopModel(modelId);
|
||||
}
|
||||
}
|
|
@ -1,197 +1,10 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.SignBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||
import net.minecraft.world.level.block.state.properties.WoodType;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import ru.betterend.blocks.entities.ESignBlockEntity;
|
||||
import ru.betterend.client.models.BlockModelProvider;
|
||||
import ru.betterend.client.models.ModelsHelper;
|
||||
import ru.betterend.interfaces.ISpetialItem;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.bclib.blocks.BaseSignBlock;
|
||||
|
||||
public class EndSignBlock extends SignBlock implements BlockModelProvider, ISpetialItem {
|
||||
public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
|
||||
public static final BooleanProperty FLOOR = BooleanProperty.create("floor");
|
||||
private static final VoxelShape[] WALL_SHAPES = new VoxelShape[] {
|
||||
Block.box(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D),
|
||||
Block.box(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D),
|
||||
Block.box(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D),
|
||||
Block.box(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D)
|
||||
};
|
||||
|
||||
private final Block parent;
|
||||
|
||||
public class EndSignBlock extends BaseSignBlock {
|
||||
public EndSignBlock(Block source) {
|
||||
super(FabricBlockSettings.copyOf(source).strength(1.0F, 1.0F).noCollission().noOcclusion(), WoodType.OAK);
|
||||
this.registerDefaultState(this.stateDefinition.any().setValue(ROTATION, 0).setValue(FLOOR, false).setValue(WATERLOGGED, false));
|
||||
this.parent = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||
builder.add(ROTATION, FLOOR, WATERLOGGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
|
||||
return state.getValue(FLOOR) ? SHAPE : WALL_SHAPES[state.getValue(ROTATION) >> 2];
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockGetter world) {
|
||||
return new ESignBlockEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
|
||||
if (placer instanceof Player) {
|
||||
ESignBlockEntity sign = (ESignBlockEntity) world.getBlockEntity(pos);
|
||||
if (sign != null) {
|
||||
if (!world.isClientSide) {
|
||||
sign.setAllowedPlayerEditor((Player) placer);
|
||||
((ServerPlayer) placer).connection.send(new ClientboundOpenSignEditorPacket(pos));
|
||||
} else {
|
||||
sign.setEditable(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
|
||||
if ((Boolean) state.getValue(WATERLOGGED)) {
|
||||
world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world));
|
||||
}
|
||||
if (!canSurvive(state, world, pos)) {
|
||||
return state.getValue(WATERLOGGED) ? state.getFluidState().createLegacyBlock() : Blocks.AIR.defaultBlockState();
|
||||
}
|
||||
return super.updateShape(state, facing, neighborState, world, pos, neighborPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
|
||||
if (!state.getValue(FLOOR)) {
|
||||
int index = (((state.getValue(ROTATION) >> 2) + 2)) & 3;
|
||||
return world.getBlockState(pos.relative(BlocksHelper.HORIZONTAL[index])).getMaterial().isSolid();
|
||||
}
|
||||
else {
|
||||
return world.getBlockState(pos.below()).getMaterial().isSolid();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
|
||||
if (ctx.getClickedFace() == Direction.UP) {
|
||||
FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos());
|
||||
return this.defaultBlockState().setValue(FLOOR, true)
|
||||
.setValue(ROTATION, Mth.floor((180.0 + ctx.getRotation() * 16.0 / 360.0) + 0.5 - 12) & 15)
|
||||
.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
|
||||
}
|
||||
else if (ctx.getClickedFace() != Direction.DOWN) {
|
||||
BlockState blockState = this.defaultBlockState();
|
||||
FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos());
|
||||
LevelReader worldView = ctx.getLevel();
|
||||
BlockPos blockPos = ctx.getClickedPos();
|
||||
Direction[] directions = ctx.getNearestLookingDirections();
|
||||
|
||||
for (Direction direction : directions) {
|
||||
if (direction.getAxis().isHorizontal()) {
|
||||
Direction dir = direction.getOpposite();
|
||||
int rot = Mth.floor((180.0 + dir.toYRot() * 16.0 / 360.0) + 0.5 + 4) & 15;
|
||||
blockState = blockState.setValue(ROTATION, rot);
|
||||
if (blockState.canSurvive(worldView, blockPos)) {
|
||||
return blockState.setValue(FLOOR, false).setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||
return ModelsHelper.createBlockEmpty(parentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, Rotation rotation) {
|
||||
return (BlockState) state.setValue(ROTATION, rotation.rotate((Integer) state.getValue(ROTATION), 16));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState mirror(BlockState state, Mirror mirror) {
|
||||
return (BlockState) state.setValue(ROTATION, mirror.mirror((Integer) state.getValue(ROTATION), 16));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
||||
return Collections.singletonList(new ItemStack(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fluid takeLiquid(LevelAccessor world, BlockPos pos, BlockState state) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackSize() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceOnWater() {
|
||||
return false;
|
||||
super(source);
|
||||
}
|
||||
}
|
|
@ -38,87 +38,13 @@ import net.minecraft.world.level.material.MaterialColor;
|
|||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import ru.bclib.blocks.BaseTerrainBlock;
|
||||
import ru.betterend.blocks.BlockSounds;
|
||||
import ru.betterend.client.models.ModelsHelper;
|
||||
import ru.betterend.client.models.Patterns;
|
||||
|
||||
public class EndTerrainBlock extends BlockBase {
|
||||
private Block pathBlock;
|
||||
|
||||
public class EndTerrainBlock extends BaseTerrainBlock {
|
||||
public EndTerrainBlock(MaterialColor color) {
|
||||
super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color).sound(BlockSounds.TERRAIN_SOUND).randomTicks());
|
||||
}
|
||||
|
||||
public void setPathBlock(Block roadBlock) {
|
||||
this.pathBlock = roadBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
|
||||
if (pathBlock != null && player.getMainHandItem().getItem().is(FabricToolTags.SHOVELS)) {
|
||||
world.playSound(player, pos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||
if (!world.isClientSide) {
|
||||
world.setBlockAndUpdate(pos, pathBlock.defaultBlockState());
|
||||
if (!player.isCreative()) {
|
||||
player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player);
|
||||
}
|
||||
}
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
||||
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
|
||||
if (tool != null && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
|
||||
return Collections.singletonList(new ItemStack(this));
|
||||
}
|
||||
return Collections.singletonList(new ItemStack(Blocks.END_STONE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
|
||||
if (random.nextInt(16) == 0 && !canStay(state, world, pos)) {
|
||||
world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canStay(BlockState state, LevelReader worldView, BlockPos pos) {
|
||||
BlockPos blockPos = pos.above();
|
||||
BlockState blockState = worldView.getBlockState(blockPos);
|
||||
if (blockState.is(Blocks.SNOW) && (Integer) blockState.getValue(SnowLayerBlock.LAYERS) == 1) {
|
||||
return true;
|
||||
}
|
||||
else if (blockState.getFluidState().getAmount() == 8) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
int i = LayerLightEngine.getLightBlockInto(worldView, state, pos, blockState, blockPos, Direction.UP, blockState.getLightBlock(worldView, blockPos));
|
||||
return i < 5;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockModel getItemModel(ResourceLocation blockId) {
|
||||
return getBlockModel(blockId, defaultBlockState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
String name = resourceLocation.getPath();
|
||||
Map<String, String> textures = Maps.newHashMap();
|
||||
textures.put("%top%", "betterend:block/" + name + "_top");
|
||||
textures.put("%side%", "betterend:block/" + name + "_side");
|
||||
textures.put("%bottom%", "minecraft:block/end_stone");
|
||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_TOP_SIDE_BOTTOM, textures);
|
||||
return ModelsHelper.fromPattern(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath());
|
||||
registerBlockModel(stateId, modelId, blockState, modelCache);
|
||||
return ModelsHelper.createRandomTopModel(modelId);
|
||||
super(Blocks.END_STONE, color);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,19 +85,19 @@ public class MetalMaterial {
|
|||
public final Item boots;
|
||||
|
||||
public static MetalMaterial makeNormal(String name, MaterialColor color, Tier material, ArmorMaterial armor) {
|
||||
return new MetalMaterial(name, true, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color), EndItems.makeItemSettings(), material, armor);
|
||||
return new MetalMaterial(name, true, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color), EndItems.makeEndItemSettings(), material, armor);
|
||||
}
|
||||
|
||||
public static MetalMaterial makeNormal(String name, MaterialColor color, float hardness, float resistance, Tier material, ArmorMaterial armor) {
|
||||
return new MetalMaterial(name, true, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color).hardness(hardness).resistance(resistance), EndItems.makeItemSettings(), material, armor);
|
||||
return new MetalMaterial(name, true, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color).hardness(hardness).resistance(resistance), EndItems.makeEndItemSettings(), material, armor);
|
||||
}
|
||||
|
||||
public static MetalMaterial makeOreless(String name, MaterialColor color, Tier material, ArmorMaterial armor) {
|
||||
return new MetalMaterial(name, false, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color), EndItems.makeItemSettings(), material, armor);
|
||||
return new MetalMaterial(name, false, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color), EndItems.makeEndItemSettings(), material, armor);
|
||||
}
|
||||
|
||||
public static MetalMaterial makeOreless(String name, MaterialColor color, float hardness, float resistance, Tier material, ArmorMaterial armor) {
|
||||
return new MetalMaterial(name, false, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color).hardness(hardness).resistance(resistance), EndItems.makeItemSettings(), material, armor);
|
||||
return new MetalMaterial(name, false, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color).hardness(hardness).resistance(resistance), EndItems.makeEndItemSettings(), material, armor);
|
||||
}
|
||||
|
||||
private MetalMaterial(String name, boolean hasOre, FabricBlockSettings settings, Properties itemSettings, Tier material, ArmorMaterial armor) {
|
||||
|
@ -120,28 +120,28 @@ public class MetalMaterial {
|
|||
bulb_lantern = EndBlocks.registerBlock(name + "_bulb_lantern", new BulbVineLanternBlock(lanternProperties));
|
||||
bulb_lantern_colored = new ColoredMaterial(BulbVineLanternColoredBlock::new, bulb_lantern, false);
|
||||
|
||||
nugget = EndItems.registerItem(name + "_nugget", new ModelProviderItem(itemSettings));
|
||||
ingot = EndItems.registerItem(name + "_ingot", new ModelProviderItem(itemSettings));
|
||||
nugget = EndItems.registerEndItem(name + "_nugget", new ModelProviderItem(itemSettings));
|
||||
ingot = EndItems.registerEndItem(name + "_ingot", new ModelProviderItem(itemSettings));
|
||||
|
||||
shovelHead = EndItems.registerItem(name + "_shovel_head");
|
||||
pickaxeHead = EndItems.registerItem(name + "_pickaxe_head");
|
||||
axeHead = EndItems.registerItem(name + "_axe_head");
|
||||
hoeHead = EndItems.registerItem(name + "_hoe_head");
|
||||
swordBlade = EndItems.registerItem(name + "_sword_blade");
|
||||
swordHandle = EndItems.registerItem(name + "_sword_handle");
|
||||
shovelHead = EndItems.registerEndItem(name + "_shovel_head");
|
||||
pickaxeHead = EndItems.registerEndItem(name + "_pickaxe_head");
|
||||
axeHead = EndItems.registerEndItem(name + "_axe_head");
|
||||
hoeHead = EndItems.registerEndItem(name + "_hoe_head");
|
||||
swordBlade = EndItems.registerEndItem(name + "_sword_blade");
|
||||
swordHandle = EndItems.registerEndItem(name + "_sword_handle");
|
||||
|
||||
shovel = EndItems.registerTool(name + "_shovel", new EndShovelItem(material, 1.5F, -3.0F, itemSettings));
|
||||
sword = EndItems.registerTool(name + "_sword", new EndSwordItem(material, 3, -2.4F, itemSettings));
|
||||
pickaxe = EndItems.registerTool(name + "_pickaxe", new EndPickaxeItem(material, 1, -2.8F, itemSettings));
|
||||
axe = EndItems.registerTool(name + "_axe", new EndAxeItem(material, 6.0F, -3.0F, itemSettings));
|
||||
hoe = EndItems.registerTool(name + "_hoe", new EndHoeItem(material, -3, 0.0F, itemSettings));
|
||||
hammer = EndItems.registerTool(name + "_hammer", new EndHammerItem(material, 5.0F, -3.2F, 0.3D, itemSettings));
|
||||
shovel = EndItems.registerEndTool(name + "_shovel", new EndShovelItem(material, 1.5F, -3.0F, itemSettings));
|
||||
sword = EndItems.registerEndTool(name + "_sword", new EndSwordItem(material, 3, -2.4F, itemSettings));
|
||||
pickaxe = EndItems.registerEndTool(name + "_pickaxe", new EndPickaxeItem(material, 1, -2.8F, itemSettings));
|
||||
axe = EndItems.registerEndTool(name + "_axe", new EndAxeItem(material, 6.0F, -3.0F, itemSettings));
|
||||
hoe = EndItems.registerEndTool(name + "_hoe", new EndHoeItem(material, -3, 0.0F, itemSettings));
|
||||
hammer = EndItems.registerEndTool(name + "_hammer", new EndHammerItem(material, 5.0F, -3.2F, 0.3D, itemSettings));
|
||||
|
||||
forgedPlate = EndItems.registerItem(name + "_forged_plate");
|
||||
helmet = EndItems.registerItem(name + "_helmet", new EndArmorItem(armor, EquipmentSlot.HEAD, itemSettings));
|
||||
chestplate = EndItems.registerItem(name + "_chestplate", new EndArmorItem(armor, EquipmentSlot.CHEST, itemSettings));
|
||||
leggings = EndItems.registerItem(name + "_leggings", new EndArmorItem(armor, EquipmentSlot.LEGS, itemSettings));
|
||||
boots = EndItems.registerItem(name + "_boots", new EndArmorItem(armor, EquipmentSlot.FEET, itemSettings));
|
||||
forgedPlate = EndItems.registerEndItem(name + "_forged_plate");
|
||||
helmet = EndItems.registerEndItem(name + "_helmet", new EndArmorItem(armor, EquipmentSlot.HEAD, itemSettings));
|
||||
chestplate = EndItems.registerEndItem(name + "_chestplate", new EndArmorItem(armor, EquipmentSlot.CHEST, itemSettings));
|
||||
leggings = EndItems.registerEndItem(name + "_leggings", new EndArmorItem(armor, EquipmentSlot.LEGS, itemSettings));
|
||||
boots = EndItems.registerEndItem(name + "_boots", new EndArmorItem(armor, EquipmentSlot.FEET, itemSettings));
|
||||
|
||||
if (hasOre) {
|
||||
FurnaceRecipe.make(name + "_ingot_furnace", ore, ingot).setGroup("end_ingot").buildWithBlasting();
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ChestMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.BarrelBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import ru.betterend.blocks.basis.EndBarrelBlock;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
|
||||
public class EBarrelBlockEntity extends RandomizableContainerBlockEntity {
|
||||
private NonNullList<ItemStack> inventory;
|
||||
private int viewerCount;
|
||||
|
||||
private EBarrelBlockEntity(BlockEntityType<?> type) {
|
||||
super(type);
|
||||
this.inventory = NonNullList.withSize(27, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
public EBarrelBlockEntity() {
|
||||
this(EndBlockEntities.BARREL);
|
||||
}
|
||||
|
||||
public CompoundTag save(CompoundTag tag) {
|
||||
super.save(tag);
|
||||
if (!this.trySaveLootTable(tag)) {
|
||||
ContainerHelper.saveAllItems(tag, this.inventory);
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void load(BlockState state, CompoundTag tag) {
|
||||
super.load(state, tag);
|
||||
this.inventory = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
|
||||
if (!this.tryLoadLootTable(tag)) {
|
||||
ContainerHelper.loadAllItems(tag, this.inventory);
|
||||
}
|
||||
}
|
||||
|
||||
public int getContainerSize() {
|
||||
return 27;
|
||||
}
|
||||
|
||||
protected NonNullList<ItemStack> getItems() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
protected void setItems(NonNullList<ItemStack> list) {
|
||||
this.inventory = list;
|
||||
}
|
||||
|
||||
protected Component getDefaultName() {
|
||||
return new TranslatableComponent("container.barrel");
|
||||
}
|
||||
|
||||
protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) {
|
||||
return ChestMenu.threeRows(syncId, playerInventory, this);
|
||||
}
|
||||
|
||||
public void startOpen(Player player) {
|
||||
if (!player.isSpectator()) {
|
||||
if (this.viewerCount < 0) {
|
||||
this.viewerCount = 0;
|
||||
}
|
||||
|
||||
++this.viewerCount;
|
||||
BlockState blockState = this.getBlockState();
|
||||
boolean bl = (Boolean) blockState.getValue(BarrelBlock.OPEN);
|
||||
if (!bl) {
|
||||
this.playSound(blockState, SoundEvents.BARREL_OPEN);
|
||||
this.setOpen(blockState, true);
|
||||
}
|
||||
|
||||
this.scheduleUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleUpdate() {
|
||||
this.level.getBlockTicks().scheduleTick(this.getBlockPos(), this.getBlockState().getBlock(), 5);
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
int i = this.worldPosition.getX();
|
||||
int j = this.worldPosition.getY();
|
||||
int k = this.worldPosition.getZ();
|
||||
this.viewerCount = ChestBlockEntity.getOpenCount(this.level, this, i, j, k);
|
||||
if (this.viewerCount > 0) {
|
||||
this.scheduleUpdate();
|
||||
} else {
|
||||
BlockState blockState = this.getBlockState();
|
||||
if (!(blockState.getBlock() instanceof EndBarrelBlock)) {
|
||||
this.setRemoved();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean bl = (Boolean) blockState.getValue(BarrelBlock.OPEN);
|
||||
if (bl) {
|
||||
this.playSound(blockState, SoundEvents.BARREL_CLOSE);
|
||||
this.setOpen(blockState, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stopOpen(Player player) {
|
||||
if (!player.isSpectator()) {
|
||||
--this.viewerCount;
|
||||
}
|
||||
}
|
||||
|
||||
private void setOpen(BlockState state, boolean open) {
|
||||
this.level.setBlock(this.getBlockPos(), (BlockState) state.setValue(BarrelBlock.OPEN, open), 3);
|
||||
}
|
||||
|
||||
private void playSound(BlockState blockState, SoundEvent soundEvent) {
|
||||
Vec3i vec3i = ((Direction) blockState.getValue(BarrelBlock.FACING)).getNormal();
|
||||
double d = (double) this.worldPosition.getX() + 0.5D + (double) vec3i.getX() / 2.0D;
|
||||
double e = (double) this.worldPosition.getY() + 0.5D + (double) vec3i.getY() / 2.0D;
|
||||
double f = (double) this.worldPosition.getZ() + 0.5D + (double) vec3i.getZ() / 2.0D;
|
||||
this.level.playSound((Player) null, d, e, f, soundEvent, SoundSource.BLOCKS, 0.5F,
|
||||
this.level.random.nextFloat() * 0.1F + 0.9F);
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
|
||||
public class EChestBlockEntity extends ChestBlockEntity {
|
||||
public EChestBlockEntity() {
|
||||
super(EndBlockEntities.CHEST);
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.FurnaceMenu;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
|
||||
public class EFurnaceBlockEntity extends AbstractFurnaceBlockEntity {
|
||||
public EFurnaceBlockEntity() {
|
||||
super(EndBlockEntities.FURNACE, RecipeType.SMELTING);
|
||||
}
|
||||
|
||||
protected Component getDefaultName() {
|
||||
return new TranslatableComponent("container.furnace");
|
||||
}
|
||||
|
||||
protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) {
|
||||
return new FurnaceMenu(syncId, playerInventory, this, this.dataAccess);
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.entity.SignBlockEntity;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
|
||||
public class ESignBlockEntity extends SignBlockEntity {
|
||||
public ESignBlockEntity() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityType<?> getType() {
|
||||
return EndBlockEntities.SIGN;
|
||||
}
|
||||
}
|
|
@ -1,179 +0,0 @@
|
|||
package ru.betterend.blocks.entities.render;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
|
||||
import net.minecraft.client.model.geom.ModelPart;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BrightnessCombiner;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.AbstractChestBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.ChestBlock;
|
||||
import net.minecraft.world.level.block.DoubleBlockCombiner;
|
||||
import net.minecraft.world.level.block.DoubleBlockCombiner.NeighborCombineResult;
|
||||
import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.LidBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.ChestType;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.basis.EndChestBlock;
|
||||
import ru.betterend.blocks.entities.EChestBlockEntity;
|
||||
import ru.betterend.registry.EndItems;
|
||||
|
||||
public class EndChestBlockEntityRenderer extends BlockEntityRenderer<EChestBlockEntity> {
|
||||
private static final HashMap<Block, RenderType[]> LAYERS = Maps.newHashMap();
|
||||
private static RenderType[] defaultLayer;
|
||||
|
||||
private static final int ID_NORMAL = 0;
|
||||
private static final int ID_LEFT = 1;
|
||||
private static final int ID_RIGHT = 2;
|
||||
|
||||
private final ModelPart partA;
|
||||
private final ModelPart partC;
|
||||
private final ModelPart partB;
|
||||
private final ModelPart partRightA;
|
||||
private final ModelPart partRightC;
|
||||
private final ModelPart partRightB;
|
||||
private final ModelPart partLeftA;
|
||||
private final ModelPart partLeftC;
|
||||
private final ModelPart partLeftB;
|
||||
|
||||
public EndChestBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher) {
|
||||
super(blockEntityRenderDispatcher);
|
||||
|
||||
this.partC = new ModelPart(64, 64, 0, 19);
|
||||
this.partC.addBox(1.0F, 0.0F, 1.0F, 14.0F, 9.0F, 14.0F, 0.0F);
|
||||
this.partA = new ModelPart(64, 64, 0, 0);
|
||||
this.partA.addBox(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F, 0.0F);
|
||||
this.partA.y = 9.0F;
|
||||
this.partA.z = 1.0F;
|
||||
this.partB = new ModelPart(64, 64, 0, 0);
|
||||
this.partB.addBox(7.0F, -1.0F, 15.0F, 2.0F, 4.0F, 1.0F, 0.0F);
|
||||
this.partB.y = 8.0F;
|
||||
this.partRightC = new ModelPart(64, 64, 0, 19);
|
||||
this.partRightC.addBox(1.0F, 0.0F, 1.0F, 15.0F, 9.0F, 14.0F, 0.0F);
|
||||
this.partRightA = new ModelPart(64, 64, 0, 0);
|
||||
this.partRightA.addBox(1.0F, 0.0F, 0.0F, 15.0F, 5.0F, 14.0F, 0.0F);
|
||||
this.partRightA.y = 9.0F;
|
||||
this.partRightA.z = 1.0F;
|
||||
this.partRightB = new ModelPart(64, 64, 0, 0);
|
||||
this.partRightB.addBox(15.0F, -1.0F, 15.0F, 1.0F, 4.0F, 1.0F, 0.0F);
|
||||
this.partRightB.y = 8.0F;
|
||||
this.partLeftC = new ModelPart(64, 64, 0, 19);
|
||||
this.partLeftC.addBox(0.0F, 0.0F, 1.0F, 15.0F, 9.0F, 14.0F, 0.0F);
|
||||
this.partLeftA = new ModelPart(64, 64, 0, 0);
|
||||
this.partLeftA.addBox(0.0F, 0.0F, 0.0F, 15.0F, 5.0F, 14.0F, 0.0F);
|
||||
this.partLeftA.y = 9.0F;
|
||||
this.partLeftA.z = 1.0F;
|
||||
this.partLeftB = new ModelPart(64, 64, 0, 0);
|
||||
this.partLeftB.addBox(0.0F, -1.0F, 15.0F, 1.0F, 4.0F, 1.0F, 0.0F);
|
||||
this.partLeftB.y = 8.0F;
|
||||
}
|
||||
|
||||
public void render(EChestBlockEntity entity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) {
|
||||
Level world = entity.getLevel();
|
||||
boolean worldExists = world != null;
|
||||
BlockState blockState = worldExists ? entity.getBlockState() : (BlockState) Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, Direction.SOUTH);
|
||||
ChestType chestType = blockState.hasProperty(ChestBlock.TYPE) ? (ChestType) blockState.getValue(ChestBlock.TYPE) : ChestType.SINGLE;
|
||||
Block block = blockState.getBlock();
|
||||
if (block instanceof AbstractChestBlock) {
|
||||
AbstractChestBlock<?> abstractChestBlock = (AbstractChestBlock<?>) block;
|
||||
boolean isDouble = chestType != ChestType.SINGLE;
|
||||
float f = ((Direction) blockState.getValue(ChestBlock.FACING)).toYRot();
|
||||
NeighborCombineResult<? extends ChestBlockEntity> propertySource;
|
||||
|
||||
matrices.pushPose();
|
||||
matrices.translate(0.5D, 0.5D, 0.5D);
|
||||
matrices.mulPose(Vector3f.YP.rotationDegrees(-f));
|
||||
matrices.translate(-0.5D, -0.5D, -0.5D);
|
||||
|
||||
if (worldExists) {
|
||||
propertySource = abstractChestBlock.combine(blockState, world, entity.getBlockPos(), true);
|
||||
} else {
|
||||
propertySource = DoubleBlockCombiner.Combiner::acceptNone;
|
||||
}
|
||||
|
||||
float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner((LidBlockEntity) entity))).get(tickDelta);
|
||||
pitch = 1.0F - pitch;
|
||||
pitch = 1.0F - pitch * pitch * pitch;
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
int blockLight = ((Int2IntFunction) propertySource.apply(new BrightnessCombiner())).applyAsInt(light);
|
||||
|
||||
VertexConsumer vertexConsumer = getConsumer(vertexConsumers, block, chestType);
|
||||
|
||||
if (isDouble) {
|
||||
if (chestType == ChestType.LEFT) {
|
||||
renderParts(matrices, vertexConsumer, this.partLeftA, this.partLeftB, this.partLeftC, pitch, blockLight, overlay);
|
||||
} else {
|
||||
renderParts(matrices, vertexConsumer, this.partRightA, this.partRightB, this.partRightC, pitch, blockLight, overlay);
|
||||
}
|
||||
} else {
|
||||
renderParts(matrices, vertexConsumer, this.partA, this.partB, this.partC, pitch, blockLight, overlay);
|
||||
}
|
||||
|
||||
matrices.popPose();
|
||||
}
|
||||
}
|
||||
|
||||
private void renderParts(PoseStack matrices, VertexConsumer vertices, ModelPart modelPart, ModelPart modelPart2, ModelPart modelPart3, float pitch, int light, int overlay) {
|
||||
modelPart.xRot = -(pitch * 1.5707964F);
|
||||
modelPart2.xRot = modelPart.xRot;
|
||||
modelPart.render(matrices, vertices, light, overlay);
|
||||
modelPart2.render(matrices, vertices, light, overlay);
|
||||
modelPart3.render(matrices, vertices, light, overlay);
|
||||
}
|
||||
|
||||
private static RenderType getChestTexture(ChestType type, RenderType[] layers) {
|
||||
switch (type) {
|
||||
case LEFT:
|
||||
return layers[ID_LEFT];
|
||||
case RIGHT:
|
||||
return layers[ID_RIGHT];
|
||||
case SINGLE:
|
||||
default:
|
||||
return layers[ID_NORMAL];
|
||||
}
|
||||
}
|
||||
|
||||
public static VertexConsumer getConsumer(MultiBufferSource provider, Block block, ChestType chestType) {
|
||||
RenderType[] layers = LAYERS.getOrDefault(block, defaultLayer);
|
||||
return provider.getBuffer(getChestTexture(chestType, layers));
|
||||
}
|
||||
|
||||
static {
|
||||
defaultLayer = new RenderType[] {
|
||||
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal.png")),
|
||||
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_left.png")),
|
||||
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_right.png"))
|
||||
};
|
||||
|
||||
EndItems.getModBlocks().forEach((item) -> {
|
||||
if (item instanceof BlockItem) {
|
||||
Block block = ((BlockItem) item).getBlock();
|
||||
if (block instanceof EndChestBlock) {
|
||||
String name = Registry.BLOCK.getKey(block).getPath();
|
||||
LAYERS.put(block, new RenderType[] {
|
||||
RenderType.entityCutout(BetterEnd.makeID("textures/entity/chest/" + name + ".png")),
|
||||
RenderType.entityCutout(BetterEnd.makeID("textures/entity/chest/" + name + "_left.png")),
|
||||
RenderType.entityCutout(BetterEnd.makeID("textures/entity/chest/" + name + "_right.png"))
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
package ru.betterend.blocks.entities.render;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.Sheets;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.SignRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.SignRenderer.SignModel;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.FormattedCharSequence;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.SignBlock;
|
||||
import net.minecraft.world.level.block.StandingSignBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.WoodType;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.basis.EndSignBlock;
|
||||
import ru.betterend.blocks.entities.ESignBlockEntity;
|
||||
import ru.betterend.registry.EndItems;
|
||||
|
||||
public class EndSignBlockEntityRenderer extends BlockEntityRenderer<ESignBlockEntity> {
|
||||
private static final HashMap<Block, RenderType> LAYERS = Maps.newHashMap();
|
||||
private static RenderType defaultLayer;
|
||||
private final SignModel model = new SignRenderer.SignModel();
|
||||
|
||||
public EndSignBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) {
|
||||
super(dispatcher);
|
||||
}
|
||||
|
||||
public void render(ESignBlockEntity signBlockEntity, float tickDelta, PoseStack matrixStack,
|
||||
MultiBufferSource provider, int light, int overlay) {
|
||||
BlockState state = signBlockEntity.getBlockState();
|
||||
matrixStack.pushPose();
|
||||
|
||||
matrixStack.translate(0.5D, 0.5D, 0.5D);
|
||||
float angle = -((float) ((Integer) state.getValue(StandingSignBlock.ROTATION) * 360) / 16.0F);
|
||||
|
||||
BlockState blockState = signBlockEntity.getBlockState();
|
||||
if (blockState.getValue(EndSignBlock.FLOOR)) {
|
||||
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle));
|
||||
this.model.stick.visible = true;
|
||||
} else {
|
||||
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle + 180));
|
||||
matrixStack.translate(0.0D, -0.3125D, -0.4375D);
|
||||
this.model.stick.visible = false;
|
||||
}
|
||||
|
||||
matrixStack.pushPose();
|
||||
matrixStack.scale(0.6666667F, -0.6666667F, -0.6666667F);
|
||||
VertexConsumer vertexConsumer = getConsumer(provider, state.getBlock());
|
||||
model.sign.render(matrixStack, vertexConsumer, light, overlay);
|
||||
model.stick.render(matrixStack, vertexConsumer, light, overlay);
|
||||
matrixStack.popPose();
|
||||
Font textRenderer = renderer.getFont();
|
||||
matrixStack.translate(0.0D, 0.3333333432674408D, 0.046666666865348816D);
|
||||
matrixStack.scale(0.010416667F, -0.010416667F, 0.010416667F);
|
||||
int m = signBlockEntity.getColor().getTextColor();
|
||||
int n = (int) (NativeImage.getR(m) * 0.4D);
|
||||
int o = (int) (NativeImage.getG(m) * 0.4D);
|
||||
int p = (int) (NativeImage.getB(m) * 0.4D);
|
||||
int q = NativeImage.combine(0, p, o, n);
|
||||
|
||||
for (int s = 0; s < 4; ++s) {
|
||||
FormattedCharSequence orderedText = signBlockEntity.getRenderMessage(s, (text) -> {
|
||||
List<FormattedCharSequence> list = textRenderer.split(text, 90);
|
||||
return list.isEmpty() ? FormattedCharSequence.EMPTY : (FormattedCharSequence) list.get(0);
|
||||
});
|
||||
if (orderedText != null) {
|
||||
float t = (float) (-textRenderer.width(orderedText) / 2);
|
||||
textRenderer.drawInBatch((FormattedCharSequence) orderedText, t, (float) (s * 10 - 20), q, false, matrixStack.last().pose(), provider, false, 0, light);
|
||||
}
|
||||
}
|
||||
|
||||
matrixStack.popPose();
|
||||
}
|
||||
|
||||
public static Material getModelTexture(Block block) {
|
||||
WoodType signType2;
|
||||
if (block instanceof SignBlock) {
|
||||
signType2 = ((SignBlock) block).type();
|
||||
} else {
|
||||
signType2 = WoodType.OAK;
|
||||
}
|
||||
|
||||
return Sheets.signTexture(signType2);
|
||||
}
|
||||
|
||||
public static VertexConsumer getConsumer(MultiBufferSource provider, Block block) {
|
||||
return provider.getBuffer(LAYERS.getOrDefault(block, defaultLayer));
|
||||
}
|
||||
|
||||
static {
|
||||
defaultLayer = RenderType.entitySolid(new ResourceLocation("textures/entity/sign/oak.png"));
|
||||
|
||||
EndItems.getModBlocks().forEach((item) -> {
|
||||
if (item instanceof BlockItem) {
|
||||
Block block = ((BlockItem) item).getBlock();
|
||||
if (block instanceof EndSignBlock) {
|
||||
String name = Registry.BLOCK.getKey(block).getPath();
|
||||
RenderType layer = RenderType.entitySolid(BetterEnd.makeID("textures/entity/sign/" + name + ".png"));
|
||||
LAYERS.put(block, layer);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
package ru.betterend.blocks.entities.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import ru.betterend.blocks.EternalPedestal;
|
||||
import ru.betterend.blocks.basis.PedestalBlock;
|
||||
import ru.betterend.blocks.entities.PedestalBlockEntity;
|
||||
import ru.betterend.client.render.BeamRenderer;
|
||||
import ru.betterend.client.render.EndCrystalRenderer;
|
||||
import ru.betterend.client.render.EternalCrystalRenderer;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndItems;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class PedestalItemRenderer<T extends PedestalBlockEntity> extends BlockEntityRenderer<T> {
|
||||
|
||||
public PedestalItemRenderer(BlockEntityRenderDispatcher dispatcher) {
|
||||
super(dispatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(T blockEntity, float tickDelta, PoseStack matrices,
|
||||
MultiBufferSource vertexConsumers, int light, int overlay) {
|
||||
|
||||
Level world = blockEntity.getLevel();
|
||||
if (world == null || blockEntity.isEmpty()) return;
|
||||
|
||||
BlockState state = world.getBlockState(blockEntity.getBlockPos());
|
||||
if (!(state.getBlock() instanceof PedestalBlock)) return;
|
||||
|
||||
ItemStack activeItem = blockEntity.getItem(0);
|
||||
|
||||
matrices.pushPose();
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
BakedModel model = minecraft.getItemRenderer().getModel(activeItem, world, null);
|
||||
Vector3f translate = model.getTransforms().ground.translation;
|
||||
PedestalBlock pedestal = (PedestalBlock) state.getBlock();
|
||||
matrices.translate(translate.x(), translate.y(), translate.z());
|
||||
matrices.translate(0.5, pedestal.getHeight(state), 0.5);
|
||||
if (activeItem.getItem() instanceof BlockItem) {
|
||||
matrices.scale(1.5F, 1.5F, 1.5F);
|
||||
} else {
|
||||
matrices.scale(1.25F, 1.25F, 1.25F);
|
||||
}
|
||||
int age = blockEntity.getAge();
|
||||
if (state.is(EndBlocks.ETERNAL_PEDESTAL) && state.getValue(EternalPedestal.ACTIVATED)) {
|
||||
float[] colors = EternalCrystalRenderer.colors(age);
|
||||
int y = blockEntity.getBlockPos().getY();
|
||||
|
||||
BeamRenderer.renderLightBeam(matrices, 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);
|
||||
}
|
||||
if (activeItem.getItem() == Items.END_CRYSTAL) {
|
||||
EndCrystalRenderer.render(age, blockEntity.getMaxAge(), tickDelta, matrices, vertexConsumers, light);
|
||||
} else if (activeItem.getItem() == EndItems.ETERNAL_CRYSTAL) {
|
||||
EternalCrystalRenderer.render(age, tickDelta, matrices, vertexConsumers, light);
|
||||
} else {
|
||||
float rotation = (age + tickDelta) / 25.0F + 6.0F;
|
||||
matrices.mulPose(Vector3f.YP.rotation(rotation));
|
||||
minecraft.getItemRenderer().render(activeItem, ItemTransforms.TransformType.GROUND, false, matrices, vertexConsumers, light, overlay, model);
|
||||
}
|
||||
matrices.popPose();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue