Skip to content

Commit

Permalink
added BlockBasicSlab, made stone slab class use it
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Dec 13, 2023
1 parent f27356a commit 1a900ae
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 11 deletions.
62 changes: 62 additions & 0 deletions common/src/main/java/muramasa/antimatter/block/BlockBasicSlab.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package muramasa.antimatter.block;

import muramasa.antimatter.AntimatterAPI;
import muramasa.antimatter.Ref;
import muramasa.antimatter.data.AntimatterStoneTypes;
import muramasa.antimatter.datagen.builder.AntimatterBlockModelBuilder;
import muramasa.antimatter.datagen.builder.VariantBlockStateBuilder;
import muramasa.antimatter.datagen.providers.AntimatterBlockStateProvider;
import muramasa.antimatter.registration.IAntimatterObject;
import muramasa.antimatter.registration.IModelProvider;
import muramasa.antimatter.registration.ISharedAntimatterObject;
import muramasa.antimatter.registration.ITextureProvider;
import muramasa.antimatter.texture.Texture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.properties.SlabType;
import net.minecraft.world.level.material.Material;

public class BlockBasicSlab extends SlabBlock implements IAntimatterObject, ITextureProvider, IModelProvider {
protected final String domain, id;

public BlockBasicSlab(String domain, String id, Properties properties) {
super(properties);
this.domain = domain;
this.id = id;
AntimatterAPI.register(getClass(), this);
}

public BlockBasicSlab(String domain, String id) {
this(domain, id, Properties.of(Material.METAL).strength(1.0f, 1.0f).sound(SoundType.STONE));
}

public String getDomain() {
return this instanceof ISharedAntimatterObject ? Ref.SHARED_ID : domain;
}

@Override
public String getId() {
return id;
}

@Override
public Texture[] getTextures() {
return new Texture[0];
}

public void onBlockModelBuild(Block block, AntimatterBlockStateProvider prov) {
Texture texture = getTextures()[0];
ResourceLocation both = prov.existing(this.getDomain(), "block/" + this.getId().replace("_slab", ""));
AntimatterBlockModelBuilder top = prov.models().getBuilder(getId() + "_top").parent(prov.existing("minecraft", "block/slab_top")).texture("bottom", texture).texture("top", texture).texture("side", texture);
AntimatterBlockModelBuilder bottom = prov.models().getBuilder(getId()).parent(prov.existing("minecraft", "block/slab")).texture("bottom", texture).texture("top", texture).texture("side", texture);
ResourceLocation finalBoth = both;
prov.getVariantBuilder(block).forAllStates(s -> {
if (s.getValue(TYPE) == SlabType.DOUBLE) {
return new VariantBlockStateBuilder.VariantBuilder().modelFile(finalBoth);
}
return new VariantBlockStateBuilder.VariantBuilder().modelFile(s.getValue(TYPE) == SlabType.TOP ? top : bottom);
});
}
}
16 changes: 5 additions & 11 deletions common/src/main/java/muramasa/antimatter/block/BlockStoneSlab.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package muramasa.antimatter.block;

import lombok.Getter;
import muramasa.antimatter.AntimatterAPI;
import muramasa.antimatter.data.AntimatterStoneTypes;
import muramasa.antimatter.datagen.builder.AntimatterBlockModelBuilder;
Expand All @@ -16,18 +17,15 @@
import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.level.block.state.properties.SlabType;

public class BlockStoneSlab extends SlabBlock implements ISharedAntimatterObject, ITextureProvider, IModelProvider {
protected String domain, id, suffix;
public class BlockStoneSlab extends BlockBasicSlab implements ISharedAntimatterObject {
@Getter
protected String suffix;
CobbleStoneType type;

public BlockStoneSlab(CobbleStoneType type, String suffix) {
super(getProps(type));
domain = type.getDomain();
String s = suffix.isEmpty() ? "" : "_";
id = type.getId() + s + suffix + "_slab";
super(type.getDomain(), type.getId() + (suffix.isEmpty() ? "" : "_") + suffix + "_slab", getProps(type));
this.suffix = suffix;
this.type = type;
AntimatterAPI.register(getClass(), this);
}

private static Properties getProps(StoneType type) {
Expand All @@ -38,10 +36,6 @@ private static Properties getProps(StoneType type) {
return props;
}

public String getSuffix() {
return suffix;
}

@Override
public String getId() {
return id;
Expand Down

0 comments on commit 1a900ae

Please sign in to comment.