Skip to content

Commit

Permalink
Add support for custom glass blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlll08 committed Jan 1, 2022
1 parent 89e566d commit b077acd
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.blamejared.contenttweaker.blocks.types.glass;

import com.blamejared.contenttweaker.VanillaFactory;
import com.blamejared.contenttweaker.api.blocks.BlockTypeBuilder;
import com.blamejared.contenttweaker.blocks.BlockBuilder;
import com.blamejared.contenttweaker.blocks.render.BlockRenderType;
import com.blamejared.crafttweaker.api.annotations.ZenRegister;
import com.blamejared.crafttweaker_annotations.annotations.Document;
import net.minecraft.util.ResourceLocation;
import org.openzen.zencode.java.ZenCodeType;

/**
* A special builder that allows you to create glass blocks.
*
* @docParam this new BlockBuilder().withType<BlockBuilderGlass>()
*/
@ZenRegister
@Document("mods/contenttweaker/API/block/basic/BlockBuilderGlass")
@ZenCodeType.Name("mods.contenttweaker.block.basic.BlockBuilderGlass")
public class BlockBuilderGlass extends BlockTypeBuilder {

public BlockBuilderGlass(BlockBuilder blockBuilder) {
super(blockBuilder);
}

@Override
public void build(ResourceLocation location) {
CoTBlockGlass blockBasic = new CoTBlockGlass(blockBuilder.getBlockProperties(), blockBuilder.getItemProperties(), location);
BlockRenderType renderType = this.blockBuilder.getRenderType();
VanillaFactory.queueBlockForRegistration(blockBasic, renderType);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.blamejared.contenttweaker.blocks.types.glass;

import com.blamejared.contenttweaker.ContentTweaker;
import com.blamejared.contenttweaker.api.blocks.IIsCoTBlock;
import com.blamejared.contenttweaker.api.items.IIsCotItem;
import com.blamejared.contenttweaker.api.resources.ImageType;
import com.blamejared.contenttweaker.api.resources.ResourceType;
import com.blamejared.contenttweaker.api.resources.WriteableResource;
import com.blamejared.contenttweaker.api.resources.WriteableResourceImage;
import com.blamejared.contenttweaker.api.resources.WriteableResourceLootTableItem;
import com.blamejared.contenttweaker.api.resources.WriteableResourceTemplate;
import com.blamejared.contenttweaker.blocks.CoTBlockItem;
import net.minecraft.block.AbstractGlassBlock;
import net.minecraft.item.Item;
import net.minecraft.loot.LootTables;
import net.minecraft.util.ResourceLocation;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection;

public class CoTBlockGlass extends AbstractGlassBlock implements IIsCoTBlock {

private final IIsCotItem item;

public CoTBlockGlass(Properties properties, Item.Properties itemProperties, ResourceLocation location) {
super(properties);
this.setRegistryName(location);
item = new CoTBlockItem(this, itemProperties);
}

@Nonnull
@Override
public IIsCotItem getItem() {
return item;
}

@Nonnull
@Override
public Collection<WriteableResource> getResourcePackResources() {
final ResourceLocation location = getRegistryNameNonNull();
final Collection<WriteableResource> out = new ArrayList<>();

out.add(WriteableResourceImage.noImage(ImageType.BLOCK, location));

final WriteableResourceTemplate modelTemplate = new WriteableResourceTemplate(ResourceType.ASSETS, location, "models", "block").withTemplate(ResourceType.ASSETS, new ResourceLocation(ContentTweaker.MOD_ID, "models/block/block_basic")).setLocationProperty(location);
out.add(modelTemplate);

final WriteableResourceTemplate blockstateTemplate = new WriteableResourceTemplate(ResourceType.ASSETS, location, "blockstates").withTemplate(ResourceType.ASSETS, new ResourceLocation(ContentTweaker.MOD_ID, "blockstates/block_basic")).setLocationProperty(location);
out.add(blockstateTemplate);

return out;
}

@Nonnull
@Override
public Collection<WriteableResource> getDataPackResources() {
final Collection<WriteableResource> out = new ArrayList<>();
if(getLootTable() != LootTables.EMPTY) {
out.add(new WriteableResourceLootTableItem(getRegistryName()));
}
return out;
}
}

0 comments on commit b077acd

Please sign in to comment.