Work around End Anvils
This commit is contained in:
parent
3668a4694a
commit
4f36d24ab2
11 changed files with 121 additions and 114 deletions
|
@ -1,69 +1,33 @@
|
|||
package ru.betterend.blocks;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||
import ru.bclib.blocks.BlockProperties;
|
||||
import ru.bclib.client.models.ModelsHelper;
|
||||
import ru.betterend.blocks.basis.EndAnvilBlock;
|
||||
import ru.betterend.client.models.Patterns;
|
||||
import ru.betterend.item.EndAnvilItem;
|
||||
import ru.betterend.item.material.EndToolMaterial;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndItems;
|
||||
|
||||
public class AeterniumAnvil extends EndAnvilBlock {
|
||||
private static final IntegerProperty DESTRUCTION_LONG = BlockProperties.DESTRUCTION_LONG;
|
||||
|
||||
|
||||
protected final Item anvilItem;
|
||||
|
||||
public AeterniumAnvil() {
|
||||
super(EndBlocks.AETERNIUM_BLOCK.defaultMaterialColor(), EndToolMaterial.AETERNIUM.getLevel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntegerProperty getDestructionProperty() {
|
||||
return DESTRUCTION_LONG;
|
||||
this.anvilItem = EndItems.registerEndItem("aeternuim_anvil_item", new EndAnvilItem(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntegerProperty getDurability() {
|
||||
if (durability == null) {
|
||||
this.maxDamage = 8;
|
||||
this.durability = IntegerProperty.create("durability", 0, maxDamage);
|
||||
this.maxDurability = 8;
|
||||
this.durability = IntegerProperty.create("durability", 0, maxDurability);
|
||||
}
|
||||
return durability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||
String name = blockId.getPath();
|
||||
int damage = getDamageState(blockState);
|
||||
Map<String, String> textures = Maps.newHashMap();
|
||||
textures.put("%anvil%", name);
|
||||
textures.put("%top%", name + "_top_" + damage);
|
||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_ANVIL, textures);
|
||||
return ModelsHelper.fromPattern(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||
int damage = getDamageState(blockState);
|
||||
String modId = stateId.getNamespace();
|
||||
String modelId = "block/" + stateId.getPath() + "_top_" + damage;
|
||||
ResourceLocation modelLocation = new ResourceLocation(modId, modelId);
|
||||
registerBlockModel(stateId, modelLocation, blockState, modelCache);
|
||||
return ModelsHelper.createFacingModel(modelLocation, blockState.getValue(FACING), false, false);
|
||||
}
|
||||
|
||||
private int getDamageState(BlockState blockState) {
|
||||
IntegerProperty destructionProperty = getDestructionProperty();
|
||||
int damage = blockState.getValue(destructionProperty);
|
||||
return damage < 3 ? 0 : damage < 6 ? 1 : 2;
|
||||
public Item asItem() {
|
||||
return anvilItem;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue