BaseAnvilBlock changes, BaseAnvilItem
This commit is contained in:
parent
72b1b237f2
commit
dcc6229769
4 changed files with 81 additions and 26 deletions
|
@ -8,7 +8,7 @@ yarn_mappings=6
|
||||||
loader_version=0.11.3
|
loader_version=0.11.3
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.1.28
|
mod_version = 0.1.29
|
||||||
maven_group = ru.bclib
|
maven_group = ru.bclib
|
||||||
archives_base_name = bclib
|
archives_base_name = bclib
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
package ru.bclib.blocks;
|
package ru.bclib.blocks;
|
||||||
|
|
||||||
import java.util.Collections;
|
import com.google.common.collect.Lists;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
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.BlockModel;
|
||||||
import net.minecraft.client.resources.model.UnbakedModel;
|
import net.minecraft.client.resources.model.UnbakedModel;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.block.AnvilBlock;
|
import net.minecraft.world.level.block.AnvilBlock;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
|
@ -22,34 +16,39 @@ import net.minecraft.world.level.block.state.StateDefinition;
|
||||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||||
import net.minecraft.world.level.material.MaterialColor;
|
import net.minecraft.world.level.material.MaterialColor;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.bclib.client.models.BasePatterns;
|
import ru.bclib.client.models.BasePatterns;
|
||||||
import ru.bclib.client.models.BlockModelProvider;
|
import ru.bclib.client.models.BlockModelProvider;
|
||||||
import ru.bclib.client.models.ModelsHelper;
|
import ru.bclib.client.models.ModelsHelper;
|
||||||
import ru.bclib.client.models.PatternsHelper;
|
import ru.bclib.client.models.PatternsHelper;
|
||||||
|
import ru.bclib.items.BaseAnvilItem;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class BaseAnvilBlock extends AnvilBlock implements BlockModelProvider {
|
public class BaseAnvilBlock extends AnvilBlock implements BlockModelProvider {
|
||||||
private static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION;
|
public static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION;
|
||||||
|
|
||||||
public BaseAnvilBlock(MaterialColor color) {
|
protected final Item anvilItem;
|
||||||
|
|
||||||
|
public BaseAnvilBlock(Item anvilItem, MaterialColor color) {
|
||||||
super(FabricBlockSettings.copyOf(Blocks.ANVIL).materialColor(color));
|
super(FabricBlockSettings.copyOf(Blocks.ANVIL).materialColor(color));
|
||||||
|
this.anvilItem = anvilItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||||
super.createBlockStateDefinition(builder);
|
super.createBlockStateDefinition(builder);
|
||||||
builder.add(getDestructionProperty());
|
builder.add(DESTRUCTION);
|
||||||
}
|
|
||||||
|
|
||||||
public IntegerProperty getDestructionProperty() {
|
|
||||||
return DESTRUCTION;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
||||||
ItemStack stack = new ItemStack(this);
|
ItemStack dropStack = new ItemStack(this);
|
||||||
int level = state.getValue(getDestructionProperty());
|
int destruction = state.getValue(DESTRUCTION);
|
||||||
stack.getOrCreateTag().putInt("level", level);
|
dropStack.getOrCreateTag().putInt(BaseAnvilItem.DESTRUCTION, destruction);
|
||||||
return Collections.singletonList(stack);
|
return Lists.newArrayList(dropStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getTop(ResourceLocation blockId, String block) {
|
protected String getTop(ResourceLocation blockId, String block) {
|
||||||
|
@ -60,6 +59,11 @@ public class BaseAnvilBlock extends AnvilBlock implements BlockModelProvider {
|
||||||
return blockId.getPath() + "_top_" + last;
|
return blockId.getPath() + "_top_" + last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item asItem() {
|
||||||
|
return anvilItem;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getItemModel(ResourceLocation blockId) {
|
public BlockModel getItemModel(ResourceLocation blockId) {
|
||||||
return getBlockModel(blockId, defaultBlockState());
|
return getBlockModel(blockId, defaultBlockState());
|
||||||
|
@ -67,8 +71,7 @@ public class BaseAnvilBlock extends AnvilBlock implements BlockModelProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
IntegerProperty destructionProperty = getDestructionProperty();
|
int destruction = blockState.getValue(DESTRUCTION);
|
||||||
int destruction = blockState.getValue(destructionProperty);
|
|
||||||
String name = blockId.getPath();
|
String name = blockId.getPath();
|
||||||
Map<String, String> textures = Maps.newHashMap();
|
Map<String, String> textures = Maps.newHashMap();
|
||||||
textures.put("%modid%", blockId.getNamespace());
|
textures.put("%modid%", blockId.getNamespace());
|
||||||
|
@ -80,8 +83,7 @@ public class BaseAnvilBlock extends AnvilBlock implements BlockModelProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
IntegerProperty destructionProperty = getDestructionProperty();
|
int destruction = blockState.getValue(DESTRUCTION);
|
||||||
int destruction = blockState.getValue(destructionProperty);
|
|
||||||
String modId = stateId.getNamespace();
|
String modId = stateId.getNamespace();
|
||||||
String modelId = "block/" + stateId.getPath() + "_top_" + destruction;
|
String modelId = "block/" + stateId.getPath() + "_top_" + destruction;
|
||||||
ResourceLocation modelLocation = new ResourceLocation(modId, modelId);
|
ResourceLocation modelLocation = new ResourceLocation(modId, modelId);
|
||||||
|
|
|
@ -16,7 +16,6 @@ public class BlockProperties {
|
||||||
public static final BooleanProperty ACTIVE = BooleanProperty.create("active");
|
public static final BooleanProperty ACTIVE = BooleanProperty.create("active");
|
||||||
public static final BooleanProperty SMALL = BooleanProperty.create("small");
|
public static final BooleanProperty SMALL = BooleanProperty.create("small");
|
||||||
|
|
||||||
public static final IntegerProperty DESTRUCTION_LONG = IntegerProperty.create("destruction", 0, 8);
|
|
||||||
public static final IntegerProperty DESTRUCTION = IntegerProperty.create("destruction", 0, 2);
|
public static final IntegerProperty DESTRUCTION = IntegerProperty.create("destruction", 0, 2);
|
||||||
public static final IntegerProperty ROTATION = IntegerProperty.create("rotation", 0, 3);
|
public static final IntegerProperty ROTATION = IntegerProperty.create("rotation", 0, 3);
|
||||||
public static final IntegerProperty FULLNESS = IntegerProperty.create("fullness", 0, 3);
|
public static final IntegerProperty FULLNESS = IntegerProperty.create("fullness", 0, 3);
|
||||||
|
|
54
src/main/java/ru/bclib/items/BaseAnvilItem.java
Normal file
54
src/main/java/ru/bclib/items/BaseAnvilItem.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
package ru.bclib.items;
|
||||||
|
|
||||||
|
import net.fabricmc.api.EnvType;
|
||||||
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.TranslatableComponent;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.item.BlockItem;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import ru.bclib.blocks.BaseAnvilBlock;
|
||||||
|
import ru.bclib.client.models.ItemModelProvider;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BaseAnvilItem extends BlockItem implements ItemModelProvider {
|
||||||
|
|
||||||
|
public final static String DESTRUCTION = "destruction";
|
||||||
|
|
||||||
|
public BaseAnvilItem(Block block, Properties properties) {
|
||||||
|
super(block, properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
|
protected BlockState getPlacementState(BlockPlaceContext blockPlaceContext) {
|
||||||
|
BlockState blockState = super.getPlacementState(blockPlaceContext);
|
||||||
|
ItemStack stack = blockPlaceContext.getItemInHand();
|
||||||
|
int destruction = stack.getOrCreateTag().getInt(DESTRUCTION);
|
||||||
|
blockState = blockState.setValue(BaseAnvilBlock.DESTRUCTION, destruction);
|
||||||
|
return blockState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Environment(EnvType.CLIENT)
|
||||||
|
public void appendHoverText(ItemStack itemStack, @Nullable Level level, List<Component> list, TooltipFlag tooltipFlag) {
|
||||||
|
super.appendHoverText(itemStack, level, list, tooltipFlag);
|
||||||
|
int l = itemStack.getOrCreateTag().getInt(DESTRUCTION);
|
||||||
|
if (l > 0) {
|
||||||
|
list.add(new TranslatableComponent("message.bclib.anvil_damage").append(": " + l));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockModel getItemModel(ResourceLocation resourceLocation) {
|
||||||
|
return ((ItemModelProvider) getBlock()).getItemModel(resourceLocation);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue