Base blocks (WIP)

This commit is contained in:
Aleksey 2021-05-26 18:00:55 +03:00
parent feb6c5172c
commit c4a510bd2e
56 changed files with 4418 additions and 1 deletions

View file

@ -0,0 +1,80 @@
package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
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.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.ButtonBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.AttachFace;
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;
public abstract class EndButtonBlock extends ButtonBlock implements BlockModelProvider {
private final Block parent;
protected EndButtonBlock(Block parent, Properties properties, boolean sensitive) {
super(sensitive, properties);
this.parent = parent;
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public BlockModel getItemModel(ResourceLocation blockId) {
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_BUTTON, parentId.getPath(), blockId.getPath());
return ModelsHelper.fromPattern(pattern);
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
Optional<String> pattern = blockState.getValue(POWERED) ?
Patterns.createJson(Patterns.BLOCK_BUTTON_PRESSED, parentId.getPath(), blockId.getPath()) :
Patterns.createJson(Patterns.BLOCK_BUTTON, parentId.getPath(), blockId.getPath());
return ModelsHelper.fromPattern(pattern);
}
@Override
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
String powered = blockState.getValue(POWERED) ? "_powered" : "";
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + powered);
registerBlockModel(stateId, modelId, blockState, modelCache);
AttachFace face = blockState.getValue(FACE);
boolean isCeiling = face == AttachFace.CEILING;
int x = 0, y = 0;
switch (face) {
case CEILING: x = 180; break;
case WALL:
default: x = 90; break;
}
switch (blockState.getValue(FACING)) {
case NORTH: if (isCeiling) { y = 180; } break;
case EAST: y = isCeiling ? 270 : 90; break;
case SOUTH: if(!isCeiling) { y = 180; } break;
case WEST:
default: y = isCeiling ? 90 : 270; break;
}
BlockModelRotation rotation = BlockModelRotation.by(x, y);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), face == AttachFace.WALL);
}
}