Skip to content

Instantly share code, notes, and snippets.

@matyklug18
Last active September 17, 2019 13:28
Show Gist options
  • Save matyklug18/5a05af203a759b98dbf3c15a8b7e34f5 to your computer and use it in GitHub Desktop.
Save matyklug18/5a05af203a759b98dbf3c15a8b7e34f5 to your computer and use it in GitHub Desktop.
public class AqaColors implements IBlockColor {
@Override
public int colorMultiplier(IBlockState state, IBlockAccess worldIn, BlockPos pos, int tintIndex) {
if(state.getBlock() instanceof RandomOreBlock) {
RandomOreBlock block = (RandomOreBlock) state.getBlock();
//worldIn.getTileEntity(pos);
if(worldIn.getTileEntity(pos) != null) {
TileRandomOre tile = (TileRandomOre) worldIn.getTileEntity(pos);
int rgb = tile.red;
rgb = (rgb << 8) + tile.green;
rgb = (rgb << 8) + tile.blue;
return rgb;
}
}
int rgb = 255;
rgb = (rgb << 8) + 255;
rgb = (rgb << 8) + 255;
return rgb;
}
}
public class CommonProxy {
public static Block blockGenerator; // this holds the unique instance of your block
public static ItemBlock itemBlockGenerator; // this holds the unique instance of the ItemBlock corresponding to your block
public static Item hungerstorer;
public static RandomOreBlock testBlock = new RandomOreBlock(Material.ROCK, 0, 0, CreativeTabs.MATERIALS);
public static TooPowerfulTNT tnt = new TooPowerfulTNT();
public void preInit(FMLPreInitializationEvent e) {
testBlock.register("test");
register("toopowerfultnt", tnt);
//testBlock.setFiles();
/*blockGenerator = new BlockGenerator().setUnlocalizedName("generator");
blockGenerator.setRegistryName("generator");
ForgeRegistries.BLOCKS.register(blockGenerator);
itemBlockGenerator = new ItemBlock(blockGenerator);
itemBlockGenerator.setRegistryName(blockGenerator.getRegistryName());
ForgeRegistries.ITEMS.register(itemBlockGenerator);
Item ring = new ItemRubyRing().setRegistryName("rubyring").setUnlocalizedName("rubyring");
ForgeRegistries.ITEMS.register(ring);
hungerstorer = new ItemHungerStorer().setRegistryName("hungerstorer").setUnlocalizedName("hungerstorer");
ForgeRegistries.ITEMS.register(hungerstorer);
GameRegistry.registerTileEntity(TileGenerator.class, Main.MODID + ":" + "generator");
NetworkRegistry.INSTANCE.registerGuiHandler(Main.instance, new GuiHandler());*/
GameRegistry.registerTileEntity(TileRandomOre.class, Main.MODID + ":" + "randomore");
EntityRegistry.registerModEntity(new ResourceLocation(Main.MODID + ":" + "deadly_projectile"), EntityProjectile.class, "deadly_projectile", 1809, Main.instance, 64, 20, false);
Main.INSTANCE.registerMessage(HungerPacketHandler.class, HungerPacket.class, 0, Side.SERVER);
Main.INSTANCE.registerMessage(KillPacketHandler.class, KillPacket.class, 0, Side.SERVER);
}
public void init(FMLInitializationEvent e) {
GameRegistry.registerWorldGenerator(new OreGen(), 0);
Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(ClientProxy.INSTANCE, CommonProxy.testBlock);
}
public void register(String name, Block block) {
String name2 = name.toLowerCase();
ForgeRegistries.BLOCKS.register(block.setRegistryName(name2.toLowerCase()).setUnlocalizedName(name2));
ForgeRegistries.ITEMS.register(new ItemBlock(block).setRegistryName(name2.toLowerCase()).setUnlocalizedName(name2));
}
}
public class RandomOreBlock extends Block{
public RandomOreBlock(Material materialIn, int hardness, int resistance, CreativeTabs tab) {
super(materialIn);
this.blockHardness = hardness;
this.blockResistance = resistance;
this.setCreativeTab(tab);
}
String name;
@Override
public boolean hasTileEntity(IBlockState state) {
return true;
}
//RandomOreTile tile;
/*@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
if(tile.getColor().getRed() > 127) {
return Items.APPLE;
} else
return Items.BAKED_POTATO;
}*/
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
super.createTileEntity(world, state);
return new TileRandomOre();
}
public void register(String name) {
this.name = name.toLowerCase();
ForgeRegistries.BLOCKS.register(this.setRegistryName(name.toLowerCase()).setUnlocalizedName(name));
ForgeRegistries.ITEMS.register(new ItemBlock(this).setRegistryName(name.toLowerCase()).setUnlocalizedName(name));
}
public void registerItemTexture() {
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(Main.MODID + ":" + name, "inventory"));
}
@Override
public BlockRenderLayer getBlockLayer() {
return BlockRenderLayer.CUTOUT;
}
}
package matyk.aqarium2.tiles;
import java.util.Random;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class TileRandomOre extends TileEntity {
public byte red, green, blue;
public TileRandomOre() {
Random rnd = new Random();
red = (byte) rnd.nextInt(255);
green = (byte) rnd.nextInt(255);
blue = (byte) rnd.nextInt(255);
}
@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
return true;
}
@Override
public void onLoad() {
super.onLoad();
world.markBlockRangeForRenderUpdate(pos, pos);
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound cmpd) {
super.writeToNBT(cmpd);
cmpd.setByte("red", red);
cmpd.setByte("green", green);
cmpd.setByte("blue", blue);
markDirty();
return cmpd;
}
@Override
public void readFromNBT(NBTTagCompound cmpd) {
super.readFromNBT(cmpd);
this.red = cmpd.getByte("red");
this.green = cmpd.getByte("green");
this.blue = cmpd.getByte("blue");
}
@Override
public NBTTagCompound getUpdateTag() {
super.getUpdateTag();
NBTTagCompound cmpd = new NBTTagCompound();
cmpd.setByte("red", red);
cmpd.setByte("green", green);
cmpd.setByte("blue", blue);
markDirty();
return cmpd;
}
@Override
public void handleUpdateTag(NBTTagCompound cmpd) {
super.handleUpdateTag(cmpd);
this.red = cmpd.getByte("red");
this.green = cmpd.getByte("green");
this.blue = cmpd.getByte("blue");
}
@Override
public SPacketUpdateTileEntity getUpdatePacket(){
NBTTagCompound cmpd = new NBTTagCompound();
cmpd.setByte("red", red);
cmpd.setByte("green", green);
cmpd.setByte("blue", blue);
markDirty();
return new SPacketUpdateTileEntity(getPos(), 1, cmpd);
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
NBTTagCompound cmpd = pkt.getNbtCompound();
this.red = cmpd.getByte("red");
this.green = cmpd.getByte("green");
this.blue = cmpd.getByte("blue");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment