Fixed Button Collision (quiqueck/BetterNether#2)

This commit is contained in:
Frank 2022-06-08 10:19:37 +02:00
parent 8940a405f8
commit 4fe6e57e05

View file

@ -1,7 +1,5 @@
package ru.bclib.blocks;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.UnbakedModel;
@ -11,7 +9,10 @@ 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 org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
@ -20,15 +21,16 @@ import ru.bclib.interfaces.LootProvider;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelProvider, LootProvider {
private final Block parent;
protected BaseButtonBlock(Block parent, Properties properties, boolean sensitive) {
super(sensitive, properties);
super(sensitive, properties.noCollission());
this.parent = parent;
}
@Override
@Environment(EnvType.CLIENT)
public BlockModel getItemModel(ResourceLocation blockId) {
@ -36,21 +38,25 @@ public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelP
Optional<String> pattern = PatternsHelper.createJson(BasePatterns.ITEM_BUTTON, parentId);
return ModelsHelper.fromPattern(pattern);
}
@Override
@Environment(EnvType.CLIENT)
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
Optional<String> pattern = blockState.getValue(POWERED) ? PatternsHelper.createJson(
BasePatterns.BLOCK_BUTTON_PRESSED,
parentId
) : PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON, parentId);
Optional<String> pattern = blockState.getValue(POWERED)
? PatternsHelper.createJson(
BasePatterns.BLOCK_BUTTON_PRESSED,
parentId
)
: PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON, parentId);
return ModelsHelper.fromPattern(pattern);
}
@Override
@Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
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);