Add helper methods to generate blockstate and models for button, pressure plate, sign to BlockStateProvider/ModelProvider (#8139)

This commit is contained in:
Dipo authored and GitHub committed 2021-10-14 20:11:20 -07:00
1 parent febfd5ab62
commit e9f8acd191
14 files changed
+270 -1

No files matched your search

@@ -29,6 +29,10 @@ import java.util.function.Function;
import javax.annotation.Nonnull;
import net.minecraft.world.level.block.ButtonBlock;
import net.minecraft.world.level.block.PressurePlateBlock;
import net.minecraft.world.level.block.StandingSignBlock;
import net.minecraft.world.level.block.WallSignBlock;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -354,6 +358,49 @@ public abstract class BlockStateProvider implements DataProvider {
.partialState().with(SlabBlock.TYPE, SlabType.DOUBLE).addModels(new ConfiguredModel(doubleslab));
}
public void buttonBlock(ButtonBlock block, ResourceLocation texture) {
ModelFile button = models().button(name(block), texture);
ModelFile buttonPressed = models().buttonPressed(name(block) + "_pressed", texture);
buttonBlock(block, button, buttonPressed);
}
public void buttonBlock(ButtonBlock block, ModelFile button, ModelFile buttonPressed) {
getVariantBuilder(block).forAllStates(state -> {
Direction facing = state.getValue(ButtonBlock.FACING);
AttachFace face = state.getValue(ButtonBlock.FACE);
boolean powered = state.getValue(ButtonBlock.POWERED);
return ConfiguredModel.builder()
.modelFile(powered ? buttonPressed : button)
.rotationX(face == AttachFace.FLOOR ? 0 : (face == AttachFace.WALL ? 90 : 180))
.rotationY((int) (face == AttachFace.CEILING ? facing : facing.getOpposite()).toYRot())
.uvLock(face == AttachFace.WALL)
.build();
});
}
public void pressurePlateBlock(PressurePlateBlock block, ResourceLocation texture) {
ModelFile pressurePlate = models().pressurePlate(name(block), texture);
ModelFile pressurePlateDown = models().pressurePlateDown(name(block) + "_down", texture);
pressurePlateBlock(block, pressurePlate, pressurePlateDown);
}
public void pressurePlateBlock(PressurePlateBlock block, ModelFile pressurePlate, ModelFile pressurePlateDown) {
getVariantBuilder(block)
.partialState().with(PressurePlateBlock.POWERED, true).addModels(new ConfiguredModel(pressurePlateDown))
.partialState().with(PressurePlateBlock.POWERED, false).addModels(new ConfiguredModel(pressurePlate));
}
public void signBlock(StandingSignBlock signBlock, WallSignBlock wallSignBlock, ResourceLocation texture) {
ModelFile sign = models().sign(name(signBlock), texture);
signBlock(signBlock, wallSignBlock, sign);
}
public void signBlock(StandingSignBlock signBlock, WallSignBlock wallSignBlock, ModelFile sign) {
simpleBlock(signBlock, sign);
simpleBlock(wallSignBlock, sign);
}
public void fourWayBlock(CrossCollisionBlock block, ModelFile post, ModelFile side) {
MultiPartBlockStateBuilder builder = getMultipartBuilder(block)
.part().modelFile(post).addModel().end();
@@ -216,6 +216,30 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements DataPr
return sideBottomTop(name, BLOCK_FOLDER + "/slab_top", side, bottom, top);
}
public T button(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/button", texture);
}
public T buttonPressed(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/button_pressed", texture);
}
public T buttonInventory(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/button_inventory", texture);
}
public T pressurePlate(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/pressure_plate_up", texture);
}
public T pressurePlateDown(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/pressure_plate_down", texture);
}
public T sign(String name, ResourceLocation texture) {
return getBuilder(name).texture("particle", texture);
}
public T fencePost(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/fence_post", texture);
}