Skip to content

Commit

Permalink
partial custom blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
unix-supremacist committed Feb 28, 2024
1 parent 7473396 commit 8cbee26
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/myname/mymodid/CommonProxy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.myname.mymodid;

import com.myname.mymodid.blocks.CustomStone;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
Expand All @@ -11,6 +12,7 @@ public class CommonProxy {
// GameRegistry." (Remove if not needed)
public void preInit(FMLPreInitializationEvent event) {
Config.synchronizeConfiguration(event.getSuggestedConfigurationFile());
CustomStone.register();

MyMod.LOG.info(Config.greeting);
MyMod.LOG.info("I am MyMod at version " + Tags.VERSION);
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/com/myname/mymodid/base/CustomBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.myname.mymodid.base;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class CustomBlock extends Block {
public String name;
Item item;
HashMap<Integer, String> subblocks;
protected IIcon[] icons;

public CustomBlock(String name, Material material, HashMap subblocks) {
super(material);
this.name = name;
this.subblocks = subblocks;
icons = new IIcon[subblocks.size()];
}

@Override
public String getUnlocalizedName() {
return "stones:"+name;
}

@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta) {
if (meta <= this.icons.length)
return this.icons[meta];
else
return this.icons[0];
}

@Override
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> list) {
for (int i = 0; i < this.subblocks.size(); ++i) {
list.add(new ItemStack(item, 1, i));
}
}

public void setDrop(Item item){
this.item = item;
}

@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int meta, int fortune) {
ArrayList<ItemStack> drops = new ArrayList<>();
ItemStack itemStack = new ItemStack(this, 1, meta);
drops.add(itemStack);
return drops;
}

@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister icon) {
for (int i = 0; i < this.icons.length; ++i) {
this.icons[i] = icon.registerIcon("stones:"+name+"_"+this.subblocks.get(i));
}
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/myname/mymodid/base/CustomItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.myname.mymodid.base;

import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemSeeds;

public class CustomItem extends ItemBlock {
public CustomItem(Block block) {
super(block);
this.setHasSubtypes(true);
}
}
34 changes: 34 additions & 0 deletions src/main/java/com/myname/mymodid/blocks/CustomStone.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.myname.mymodid.blocks;

import com.myname.mymodid.base.CustomBlock;
import com.myname.mymodid.base.CustomItem;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;

import java.util.HashMap;

public class CustomStone{
static HashMap<Integer, String> subblocks = new HashMap<>();
public enum Stones {
BRICKS,
CHISELED;

Stones() {
subblocks.put(this.ordinal(), this.name());
}
}

public static void register(){
Stones.values();
CustomBlock block = new CustomBlock("custom_block", Material.rock, subblocks);
//ItemBlock item = new CustomItem(block);
//block.setDrop(item);
//GameRegistry.registerItem(item, block.name);
GameRegistry.registerBlock(block, block.name);
}
}

0 comments on commit 8cbee26

Please sign in to comment.