Last active
September 18, 2019 13:25
-
-
Save matyklug18/c35f2df41b10ae503c9967c04a92b131 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package matyk.aqarium2.eventHandler; | |
import matyk.aqarium2.main.Main; | |
import net.minecraft.client.renderer.block.model.ModelResourceLocation; | |
import net.minecraft.item.Item; | |
import net.minecraftforge.client.event.ModelRegistryEvent; | |
import net.minecraftforge.client.model.ModelLoader; | |
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | |
public class ClientEventHandler { | |
@SubscribeEvent | |
public void registerModels(ModelRegistryEvent event) { | |
String name = "randore"; | |
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(EventHandler.testBlock), 0, new ModelResourceLocation(Main.MODID + ":" + name, "inventory")); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SubscribeEvent | |
public void registerBlocks(RegistryEvent.Register<Block> event) { | |
testBlock = new RandomOreBlock(Material.ROCK, 0, 0, CreativeTabs.MATERIALS); | |
event.getRegistry().registerAll(testBlock.setRegistryName("randore").setUnlocalizedName(Main.MODID + ":" +"randore")); | |
} | |
@SubscribeEvent | |
public void registerItems(RegistryEvent.Register<Item> event) { | |
String name = "randore"; | |
event.getRegistry().registerAll(new ItemBlock(testBlock).setRegistryName("randore")); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package matyk.aqarium2.tiles; | |
import java.util.Random; | |
import matyk.aqarium2.main.Main; | |
import net.minecraft.block.state.IBlockState; | |
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; | |
import net.minecraftforge.fml.common.network.NetworkRegistry; | |
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | |
public class TileRandomOre extends TileEntity { | |
public byte red = 100, green = 100, blue = 100; | |
public TileRandomOre() { | |
} | |
@Override | |
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) { | |
world.notifyBlockUpdate(pos, oldState, newState, 3); | |
return true; | |
} | |
@Override | |
public void onLoad() { | |
super.onLoad(); | |
world.markBlockRangeForRenderUpdate(pos, pos); | |
world.getBlockState(pos); | |
world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 3); | |
} | |
@Override | |
public void onChunkUnload() { | |
super.onChunkUnload(); | |
} | |
@Override | |
public NBTTagCompound writeToNBT(NBTTagCompound cmpd) { | |
super.writeToNBT(cmpd); | |
cmpd.setByte("red", red); | |
cmpd.setByte("green", green); | |
cmpd.setByte("blue", blue); | |
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); | |
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() { | |
super.getUpdatePacket(); | |
NBTTagCompound cmpd = new NBTTagCompound(); | |
cmpd.setByte("red", red); | |
cmpd.setByte("green", green); | |
cmpd.setByte("blue", blue); | |
return new SPacketUpdateTileEntity(getPos(), 1, cmpd); | |
} | |
@Override | |
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { | |
super.onDataPacket(net, 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