Change models loading (yes, WIP)
This commit is contained in:
parent
9b67bc5719
commit
52fc329a0a
8 changed files with 98 additions and 17 deletions
|
@ -7,6 +7,7 @@ import com.google.common.collect.Maps;
|
|||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -18,6 +19,7 @@ import net.minecraft.world.level.material.Material;
|
|||
import net.minecraft.world.level.material.MaterialColor;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.betterend.blocks.basis.EndLanternBlock;
|
||||
import ru.betterend.client.render.ERenderLayer;
|
||||
import ru.betterend.interfaces.IRenderTypeable;
|
||||
|
@ -67,6 +69,17 @@ public class BulbVineLanternBlock extends EndLanternBlock implements IRenderType
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
Map<String, String> textures = Maps.newHashMap();
|
||||
textures.put("%glow%", getGlowTexture());
|
||||
textures.put("%metal%", getMetalTexture(resourceLocation));
|
||||
Optional<String> pattern = blockState.getValue(IS_FLOOR) ?
|
||||
Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_FLOOR, textures) :
|
||||
Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_CEIL, textures);
|
||||
return pattern.map(BlockModel::fromString).orElse(null);
|
||||
}
|
||||
|
||||
protected String getMetalTexture(ResourceLocation blockId) {
|
||||
String name = blockId.getPath();
|
||||
name = name.substring(0, name.indexOf('_'));
|
||||
|
|
|
@ -14,16 +14,12 @@ public class BulbVineLanternColoredBlock extends BulbVineLanternBlock implements
|
|||
|
||||
@Override
|
||||
public BlockColor getProvider() {
|
||||
return (state, world, pos, tintIndex) -> {
|
||||
return getColor();
|
||||
};
|
||||
return (state, world, pos, tintIndex) -> getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemColor getItemProvider() {
|
||||
return (stack, tintIndex) -> {
|
||||
return getColor();
|
||||
};
|
||||
return (stack, tintIndex) -> getColor();
|
||||
}
|
||||
|
||||
private int getColor() {
|
||||
|
|
|
@ -15,6 +15,7 @@ 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.betterend.client.models.BlockModelProvider;
|
||||
import ru.betterend.client.models.ModelsHelper;
|
||||
import ru.betterend.client.models.Patterns;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
|
||||
|
@ -59,7 +60,6 @@ public class EndChestBlock extends ChestBlock implements BlockModelProvider {
|
|||
@Override
|
||||
public BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_EMPTY, parentId.getPath());
|
||||
return pattern.map(BlockModel::fromString).orElse(null);
|
||||
return ModelsHelper.createBlockEmpty(parentId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||
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.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
|
@ -19,6 +22,9 @@ import net.minecraft.world.level.material.Fluid;
|
|||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import ru.betterend.blocks.BlockProperties;
|
||||
import ru.betterend.client.models.ModelsHelper;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class EndLanternBlock extends BlockBaseNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer {
|
||||
public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR;
|
||||
|
@ -116,4 +122,13 @@ public class EndLanternBlock extends BlockBaseNotFull implements SimpleWaterlogg
|
|||
public FluidState getFluidState(BlockState state) {
|
||||
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||
String floor = blockState.getValue(IS_FLOOR) ? "_floor" : "";
|
||||
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
||||
"block/" + resourceLocation.getPath() + floor);
|
||||
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||
return ModelsHelper.createBlockSimple(modelId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
|
||||
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;
|
||||
|
@ -38,7 +39,9 @@ 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 org.jetbrains.annotations.Nullable;
|
||||
import ru.betterend.blocks.entities.ESignBlockEntity;
|
||||
import ru.betterend.client.models.ModelsHelper;
|
||||
import ru.betterend.interfaces.ISpetialItem;
|
||||
import ru.betterend.client.models.BlockModelProvider;
|
||||
import ru.betterend.client.models.Patterns;
|
||||
|
@ -79,17 +82,18 @@ public class EndSignBlock extends SignBlock implements BlockModelProvider, ISpet
|
|||
|
||||
@Override
|
||||
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
|
||||
if (placer != null && placer instanceof Player) {
|
||||
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 {
|
||||
} else {
|
||||
sign.setEditable(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
|
||||
|
@ -128,8 +132,7 @@ public class EndSignBlock extends SignBlock implements BlockModelProvider, ISpet
|
|||
BlockPos blockPos = ctx.getClickedPos();
|
||||
Direction[] directions = ctx.getNearestLookingDirections();
|
||||
|
||||
for (int i = 0; i < directions.length; ++i) {
|
||||
Direction direction = directions[i];
|
||||
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;
|
||||
|
@ -153,6 +156,12 @@ public class EndSignBlock extends SignBlock implements BlockModelProvider, ISpet
|
|||
return Patterns.createJson(Patterns.BLOCK_EMPTY, parentId.getPath());
|
||||
}
|
||||
|
||||
@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));
|
||||
|
|
|
@ -2,17 +2,27 @@ package ru.betterend.blocks.basis;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||
import net.minecraft.client.renderer.block.model.Variant;
|
||||
import net.minecraft.client.resources.model.BlockModelRotation;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.SlabBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.SlabType;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.betterend.client.models.BlockModelProvider;
|
||||
import ru.betterend.client.models.ModelsHelper;
|
||||
import ru.betterend.client.models.Patterns;
|
||||
|
||||
public class EndSlabBlock extends SlabBlock implements BlockModelProvider {
|
||||
|
@ -35,4 +45,24 @@ public class EndSlabBlock extends SlabBlock implements BlockModelProvider {
|
|||
return Patterns.createJson(Patterns.BLOCK_SLAB, parentId.getPath(), blockId.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_SLAB, parentId.getPath(), blockId.getPath());
|
||||
return pattern.map(BlockModel::fromString).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||
SlabType type = blockState.getValue(TYPE);
|
||||
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
||||
"block/" + resourceLocation.getPath() + "_" + type);
|
||||
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||
if (type == SlabType.TOP) {
|
||||
BlockModelRotation rotation = BlockModelRotation.by(180, 0);
|
||||
Variant variant = new Variant(modelId, rotation.getRotation(), true, 1);
|
||||
return new MultiVariant(Lists.newArrayList(variant));
|
||||
}
|
||||
return ModelsHelper.createBlockSimple(modelId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,15 +5,18 @@ import java.util.Optional;
|
|||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.client.color.block.BlockColor;
|
||||
import net.minecraft.client.color.item.ItemColor;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.betterend.blocks.AuroraCrystalBlock;
|
||||
import ru.betterend.interfaces.IColorProvider;
|
||||
import ru.betterend.client.models.Patterns;
|
||||
|
@ -70,4 +73,12 @@ public class StoneLanternBlock extends EndLanternBlock implements IColorProvider
|
|||
return Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_FLOOR, texture, texture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||
String blockName = resourceLocation.getPath();
|
||||
Optional<String> pattern = blockState.getValue(IS_FLOOR) ?
|
||||
Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_FLOOR, blockName, blockName) :
|
||||
Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_CEIL, blockName, blockName);
|
||||
return pattern.map(BlockModel::fromString).orElse(null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,9 @@ import net.minecraft.client.renderer.block.model.MultiVariant;
|
|||
import net.minecraft.client.renderer.block.model.Variant;
|
||||
import net.minecraft.client.resources.model.BlockModelRotation;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -25,6 +27,11 @@ public class ModelsHelper {
|
|||
return pattern.map(BlockModel::fromString).orElse(null);
|
||||
}
|
||||
|
||||
public static BlockModel createBlockEmpty(ResourceLocation resourceLocation) {
|
||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_EMPTY, resourceLocation.getPath());
|
||||
return pattern.map(BlockModel::fromString).orElse(null);
|
||||
}
|
||||
|
||||
public static MultiVariant createBlockSimple(ResourceLocation resourceLocation) {
|
||||
Variant variant = new Variant(resourceLocation, Transformation.identity(), false, 1);
|
||||
return new MultiVariant(Lists.newArrayList(variant));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue