提供: Minecraft Modding Wiki
この編集を取り消せます。
下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 | 編集中の文章 | ||
8行目: | 8行目: | ||
*SampleTileEntityCore.java | *SampleTileEntityCore.java | ||
<source lang = "java"> | <source lang = "java"> | ||
− | package mods. | + | package mods.tileentitysample; |
− | + | ||
import net.minecraft.block.Block; | import net.minecraft.block.Block; | ||
import net.minecraft.block.material.Material; | import net.minecraft.block.material.Material; | ||
21行目: | 21行目: | ||
import cpw.mods.fml.common.registry.GameRegistry; | import cpw.mods.fml.common.registry.GameRegistry; | ||
import cpw.mods.fml.common.registry.LanguageRegistry; | import cpw.mods.fml.common.registry.LanguageRegistry; | ||
− | + | ||
@Mod(modid="TileEntitySampleMod", name="TileEntitySampleMod", version="1.0") | @Mod(modid="TileEntitySampleMod", name="TileEntitySampleMod", version="1.0") | ||
− | @NetworkMod( | + | @NetworkMod(channels = "updateTile", packetHandler = PacketHandler.class) |
public class SampleTileEntityCore { | public class SampleTileEntityCore { | ||
− | + | ||
public static Block blockSample; | public static Block blockSample; | ||
public static int blockSampleID = 4087; | public static int blockSampleID = 4087; | ||
− | + | ||
public static int guiSampleID = 1000; | public static int guiSampleID = 1000; | ||
34行目: | 34行目: | ||
@Instance("TileEntitySampleMod") | @Instance("TileEntitySampleMod") | ||
public static SampleTileEntityCore instance; | public static SampleTileEntityCore instance; | ||
− | + | ||
@EventHandler | @EventHandler | ||
public void init(FMLInitializationEvent event) | public void init(FMLInitializationEvent event) | ||
41行目: | 41行目: | ||
LanguageRegistry.addName(blockSample, "Sample Block"); | LanguageRegistry.addName(blockSample, "Sample Block"); | ||
LanguageRegistry.instance().addNameForObject(blockSample, "ja_JP", "サンプル ブロック"); | LanguageRegistry.instance().addNameForObject(blockSample, "ja_JP", "サンプル ブロック"); | ||
− | + | ||
//TileEntityの登録 | //TileEntityの登録 | ||
GameRegistry.registerTileEntity(TileEntitySample.class, "TileEntitySample"); | GameRegistry.registerTileEntity(TileEntitySample.class, "TileEntitySample"); | ||
− | + | ||
//GUIの登録 | //GUIの登録 | ||
NetworkRegistry.instance().registerGuiHandler(this, new GuiHandler()); | NetworkRegistry.instance().registerGuiHandler(this, new GuiHandler()); | ||
56行目: | 56行目: | ||
GameRegistry.registerBlock(blockSample, "blockSample"); | GameRegistry.registerBlock(blockSample, "blockSample"); | ||
} | } | ||
− | + | ||
} | } | ||
63行目: | 63行目: | ||
*BlockContainerSample.java | *BlockContainerSample.java | ||
<source lang = "java"> | <source lang = "java"> | ||
− | package mods. | + | package mods.tileentitysample; |
− | + | ||
+ | import java.util.Random; | ||
+ | |||
import net.minecraft.block.BlockContainer; | import net.minecraft.block.BlockContainer; | ||
import net.minecraft.block.material.Material; | import net.minecraft.block.material.Material; | ||
73行目: | 75行目: | ||
import net.minecraft.tileentity.TileEntity; | import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.world.World; | import net.minecraft.world.World; | ||
− | + | ||
public class BlockContainerSample extends BlockContainer { | public class BlockContainerSample extends BlockContainer { | ||
− | + | ||
+ | protected Random rand = new Random(); | ||
+ | |||
protected BlockContainerSample(int par1, Material par2Material) { | protected BlockContainerSample(int par1, Material par2Material) { | ||
super(par1, par2Material); | super(par1, par2Material); | ||
} | } | ||
− | + | ||
//右クリックされた時の処理 | //右クリックされた時の処理 | ||
@Override | @Override | ||
94行目: | 98行目: | ||
} | } | ||
} | } | ||
− | + | ||
//ブロックが壊れた時の処理 | //ブロックが壊れた時の処理 | ||
//周辺に中に入っていたアイテムをまき散らす | //周辺に中に入っていたアイテムをまき散らす | ||
101行目: | 105行目: | ||
{ | { | ||
TileEntitySample tileentity = (TileEntitySample) par1World.getBlockTileEntity(par2, par3, par4); | TileEntitySample tileentity = (TileEntitySample) par1World.getBlockTileEntity(par2, par3, par4); | ||
− | + | ||
if (tileentity != null) | if (tileentity != null) | ||
{ | { | ||
− | for (int j1 = 0; j1 < tileentity.getSizeInventory(); ++j1) | + | for (int j1 = 0; j1 < tileentity.inventory.getSizeInventory(); ++j1) |
{ | { | ||
− | ItemStack itemstack = tileentity.getStackInSlot(j1); | + | ItemStack itemstack = tileentity.inventory.getStackInSlot(j1); |
− | + | ||
if (itemstack != null) | if (itemstack != null) | ||
{ | { | ||
− | float f = | + | float f = this.rand.nextFloat() * 0.8F + 0.1F; |
− | float f1 = | + | float f1 = this.rand.nextFloat() * 0.8F + 0.1F; |
− | float f2 = | + | float f2 = this.rand.nextFloat() * 0.8F + 0.1F; |
− | + | ||
while (itemstack.stackSize > 0) | while (itemstack.stackSize > 0) | ||
{ | { | ||
− | int k1 = | + | int k1 = this.rand.nextInt(21) + 10; |
− | + | ||
if (k1 > itemstack.stackSize) | if (k1 > itemstack.stackSize) | ||
{ | { | ||
k1 = itemstack.stackSize; | k1 = itemstack.stackSize; | ||
} | } | ||
− | + | ||
itemstack.stackSize -= k1; | itemstack.stackSize -= k1; | ||
EntityItem entityitem = new EntityItem(par1World, (double)((float)par2 + f), (double)((float)par3 + f1), (double)((float)par4 + f2), new ItemStack(itemstack.itemID, k1, itemstack.getItemDamage())); | EntityItem entityitem = new EntityItem(par1World, (double)((float)par2 + f), (double)((float)par3 + f1), (double)((float)par4 + f2), new ItemStack(itemstack.itemID, k1, itemstack.getItemDamage())); | ||
− | + | ||
if (itemstack.hasTagCompound()) | if (itemstack.hasTagCompound()) | ||
{ | { | ||
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); | entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); | ||
} | } | ||
− | + | ||
float f3 = 0.05F; | float f3 = 0.05F; | ||
− | entityitem.motionX = (double)((float) | + | entityitem.motionX = (double)((float)this.rand.nextGaussian() * f3); |
− | entityitem.motionY = (double)((float) | + | entityitem.motionY = (double)((float)this.rand.nextGaussian() * f3 + 0.2F); |
− | entityitem.motionZ = (double)((float) | + | entityitem.motionZ = (double)((float)this.rand.nextGaussian() * f3); |
par1World.spawnEntityInWorld(entityitem); | par1World.spawnEntityInWorld(entityitem); | ||
} | } | ||
} | } | ||
} | } | ||
− | + | ||
par1World.func_96440_m(par2, par3, par4, par5); | par1World.func_96440_m(par2, par3, par4, par5); | ||
} | } | ||
− | + | ||
super.breakBlock(par1World, par2, par3, par4, par5, par6); | super.breakBlock(par1World, par2, par3, par4, par5, par6); | ||
} | } | ||
− | + | ||
@Override | @Override | ||
public TileEntity createNewTileEntity(World world) { | public TileEntity createNewTileEntity(World world) { | ||
151行目: | 155行目: | ||
return new TileEntitySample(); | return new TileEntitySample(); | ||
} | } | ||
− | + | ||
} | } | ||
158行目: | 162行目: | ||
*TileEntitySample.java | *TileEntitySample.java | ||
<source lang = "java"> | <source lang = "java"> | ||
− | package mods. | + | package mods.tileentitysample; |
− | + | ||
+ | import java.io.DataOutputStream; | ||
+ | import java.io.IOException; | ||
+ | |||
import net.minecraft.block.Block; | import net.minecraft.block.Block; | ||
import net.minecraft.block.material.Material; | import net.minecraft.block.material.Material; | ||
− | |||
− | |||
import net.minecraft.item.Item; | import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemBlock; | import net.minecraft.item.ItemBlock; | ||
173行目: | 178行目: | ||
import net.minecraft.nbt.NBTTagCompound; | import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.nbt.NBTTagList; | import net.minecraft.nbt.NBTTagList; | ||
− | |||
import net.minecraft.network.packet.Packet; | import net.minecraft.network.packet.Packet; | ||
− | |||
import net.minecraft.tileentity.TileEntity; | import net.minecraft.tileentity.TileEntity; | ||
+ | |||
+ | import com.google.common.io.ByteArrayDataInput; | ||
+ | |||
import cpw.mods.fml.common.registry.GameRegistry; | import cpw.mods.fml.common.registry.GameRegistry; | ||
import cpw.mods.fml.relauncher.Side; | import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | import cpw.mods.fml.relauncher.SideOnly; | ||
− | + | ||
− | public class TileEntitySample extends TileEntity | + | public class TileEntitySample extends TileEntity |
{ | { | ||
− | + | ||
//燃焼時間 | //燃焼時間 | ||
public int burnTime; | public int burnTime; | ||
− | + | ||
public int currentItemBurnTime; | public int currentItemBurnTime; | ||
− | + | ||
//調理時間 | //調理時間 | ||
public int cookTime; | public int cookTime; | ||
− | + | ||
− | + | public InventorySample inventory; | |
− | + | ||
− | + | public TileEntitySample() { | |
− | + | this.inventory = new InventorySample(this); | |
− | + | } | |
− | + | ||
@Override | @Override | ||
public void readFromNBT(NBTTagCompound par1NBTTagCompound) | public void readFromNBT(NBTTagCompound par1NBTTagCompound) | ||
{ | { | ||
super.readFromNBT(par1NBTTagCompound); | super.readFromNBT(par1NBTTagCompound); | ||
− | + | ||
//アイテムの読み込み | //アイテムの読み込み | ||
NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items"); | NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items"); | ||
− | this.sampleItemStacks = new ItemStack[this.getSizeInventory()]; | + | this.inventory.sampleItemStacks = new ItemStack[this.inventory.getSizeInventory()]; |
− | + | ||
for (int i = 0; i < nbttaglist.tagCount(); ++i) | for (int i = 0; i < nbttaglist.tagCount(); ++i) | ||
{ | { | ||
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i); | NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i); | ||
byte b0 = nbttagcompound1.getByte("Slot"); | byte b0 = nbttagcompound1.getByte("Slot"); | ||
− | + | ||
− | if (b0 >= 0 && b0 < this.sampleItemStacks.length) | + | if (b0 >= 0 && b0 < this.inventory.sampleItemStacks.length) |
{ | { | ||
− | this.sampleItemStacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); | + | this.inventory.sampleItemStacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); |
} | } | ||
} | } | ||
− | + | ||
//燃焼時間や調理時間などの読み込み | //燃焼時間や調理時間などの読み込み | ||
this.burnTime = par1NBTTagCompound.getShort("BurnTime"); | this.burnTime = par1NBTTagCompound.getShort("BurnTime"); | ||
this.cookTime = par1NBTTagCompound.getShort("CookTime"); | this.cookTime = par1NBTTagCompound.getShort("CookTime"); | ||
− | this.currentItemBurnTime = getItemBurnTime(this.sampleItemStacks[1]); | + | this.currentItemBurnTime = getItemBurnTime(this.inventory.sampleItemStacks[1]); |
− | + | ||
} | } | ||
− | + | ||
@Override | @Override | ||
public void writeToNBT(NBTTagCompound par1NBTTagCompound) | public void writeToNBT(NBTTagCompound par1NBTTagCompound) | ||
{ | { | ||
super.writeToNBT(par1NBTTagCompound); | super.writeToNBT(par1NBTTagCompound); | ||
− | + | ||
//燃焼時間や調理時間などの書き込み | //燃焼時間や調理時間などの書き込み | ||
par1NBTTagCompound.setShort("BurnTime", (short)this.burnTime); | par1NBTTagCompound.setShort("BurnTime", (short)this.burnTime); | ||
par1NBTTagCompound.setShort("CookTime", (short)this.cookTime); | par1NBTTagCompound.setShort("CookTime", (short)this.cookTime); | ||
− | + | ||
//アイテムの書き込み | //アイテムの書き込み | ||
NBTTagList nbttaglist = new NBTTagList(); | NBTTagList nbttaglist = new NBTTagList(); | ||
− | + | ||
− | for (int i = 0; i < this.sampleItemStacks.length; ++i) | + | for (int i = 0; i < this.inventory.sampleItemStacks.length; ++i) |
{ | { | ||
− | if (this.sampleItemStacks[i] != null) | + | if (this.inventory.sampleItemStacks[i] != null) |
{ | { | ||
NBTTagCompound nbttagcompound1 = new NBTTagCompound(); | NBTTagCompound nbttagcompound1 = new NBTTagCompound(); | ||
nbttagcompound1.setByte("Slot", (byte)i); | nbttagcompound1.setByte("Slot", (byte)i); | ||
− | this.sampleItemStacks[i].writeToNBT(nbttagcompound1); | + | this.inventory.sampleItemStacks[i].writeToNBT(nbttagcompound1); |
nbttaglist.appendTag(nbttagcompound1); | nbttaglist.appendTag(nbttagcompound1); | ||
} | } | ||
} | } | ||
− | + | ||
par1NBTTagCompound.setTag("Items", nbttaglist); | par1NBTTagCompound.setTag("Items", nbttaglist); | ||
− | + | ||
+ | } | ||
+ | |||
+ | public void readToPacket(ByteArrayDataInput data) { | ||
+ | //アイテムの読み込み | ||
+ | for (int i = 0; i < this.inventory.getSizeInventory(); i++) { | ||
+ | int id = data.readInt(); | ||
+ | int stacksize = data.readByte(); | ||
+ | int metadata = data.readInt(); | ||
+ | |||
+ | if (id != 0 && stacksize != 0) { | ||
+ | this.inventory.setInventorySlotContents(i, new ItemStack(id, stacksize, metadata)); | ||
+ | } else { | ||
+ | this.inventory.setInventorySlotContents(i, null); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | public void writeToPacket(DataOutputStream dos) { | ||
+ | try { | ||
+ | //アイテムの書き込み | ||
+ | for (int i = 0; i < this.inventory.getSizeInventory(); i++) { | ||
+ | int id = this.inventory.sampleItemStacks[i] != null ? this.inventory.sampleItemStacks[i].itemID : 0; | ||
+ | int stacksize = this.inventory.sampleItemStacks[i] != null ? this.inventory.sampleItemStacks[i].stackSize : 0; | ||
+ | int metadata = this.inventory.sampleItemStacks[i] != null ? this.inventory.sampleItemStacks[i].getItemDamage() : 0; | ||
+ | |||
+ | dos.writeInt(id); | ||
+ | dos.writeByte(stacksize); | ||
+ | dos.writeInt(metadata); | ||
+ | } | ||
+ | } catch (IOException e) { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
} | } | ||
− | + | ||
@Override | @Override | ||
− | public Packet getDescriptionPacket() { | + | public Packet getDescriptionPacket() |
− | + | { | |
− | + | //パケットの取得 | |
− | + | return PacketHandler.getPacket(this); | |
} | } | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
//かまどの処理 | //かまどの処理 | ||
@SideOnly(Side.CLIENT) | @SideOnly(Side.CLIENT) | ||
270行目: | 303行目: | ||
return this.cookTime * par1 / 200; | return this.cookTime * par1 / 200; | ||
} | } | ||
− | + | ||
//かまどの処理 | //かまどの処理 | ||
@SideOnly(Side.CLIENT) | @SideOnly(Side.CLIENT) | ||
279行目: | 312行目: | ||
this.currentItemBurnTime = 200; | this.currentItemBurnTime = 200; | ||
} | } | ||
− | + | ||
return this.burnTime * par1 / this.currentItemBurnTime; | return this.burnTime * par1 / this.currentItemBurnTime; | ||
} | } | ||
− | + | ||
//かまどの処理 | //かまどの処理 | ||
public boolean isBurning() | public boolean isBurning() | ||
288行目: | 321行目: | ||
return this.burnTime > 0; | return this.burnTime > 0; | ||
} | } | ||
− | + | ||
//更新時に呼び出される | //更新時に呼び出される | ||
//かまどの処理 | //かまどの処理 | ||
295行目: | 328行目: | ||
boolean flag = this.burnTime > 0; | boolean flag = this.burnTime > 0; | ||
boolean flag1 = false; | boolean flag1 = false; | ||
− | + | ||
if (this.burnTime > 0) | if (this.burnTime > 0) | ||
{ | { | ||
--this.burnTime; | --this.burnTime; | ||
} | } | ||
− | + | ||
if (!this.worldObj.isRemote) | if (!this.worldObj.isRemote) | ||
{ | { | ||
if (this.burnTime == 0 && this.canSmelt()) | if (this.burnTime == 0 && this.canSmelt()) | ||
{ | { | ||
− | this.currentItemBurnTime = this.burnTime = getItemBurnTime(this.sampleItemStacks[1]); | + | this.currentItemBurnTime = this.burnTime = getItemBurnTime(this.inventory.sampleItemStacks[1]); |
− | + | ||
if (this.burnTime > 0) | if (this.burnTime > 0) | ||
{ | { | ||
flag1 = true; | flag1 = true; | ||
− | + | ||
− | if (this.sampleItemStacks[1] != null) | + | if (this.inventory.sampleItemStacks[1] != null) |
{ | { | ||
− | --this.sampleItemStacks[1].stackSize; | + | --this.inventory.sampleItemStacks[1].stackSize; |
− | + | ||
− | if (this.sampleItemStacks[1].stackSize == 0) | + | if (this.inventory.sampleItemStacks[1].stackSize == 0) |
{ | { | ||
− | this.sampleItemStacks[1] = this.sampleItemStacks[1].getItem().getContainerItemStack(this.sampleItemStacks[1]); | + | this.inventory.sampleItemStacks[1] = this.inventory.sampleItemStacks[1].getItem().getContainerItemStack(this.inventory.sampleItemStacks[1]); |
} | } | ||
} | } | ||
} | } | ||
} | } | ||
− | + | ||
if (this.isBurning() && this.canSmelt()) | if (this.isBurning() && this.canSmelt()) | ||
{ | { | ||
++this.cookTime; | ++this.cookTime; | ||
− | + | ||
if (this.cookTime == 200) | if (this.cookTime == 200) | ||
{ | { | ||
338行目: | 371行目: | ||
this.cookTime = 0; | this.cookTime = 0; | ||
} | } | ||
− | + | ||
if (flag != this.burnTime > 0) | if (flag != this.burnTime > 0) | ||
{ | { | ||
344行目: | 377行目: | ||
} | } | ||
} | } | ||
− | + | ||
if (flag1) | if (flag1) | ||
{ | { | ||
350行目: | 383行目: | ||
} | } | ||
} | } | ||
− | + | ||
//かまどの処理 | //かまどの処理 | ||
private boolean canSmelt() | private boolean canSmelt() | ||
{ | { | ||
− | if (this.sampleItemStacks[0] == null) | + | if (this.inventory.sampleItemStacks[0] == null) |
{ | { | ||
return false; | return false; | ||
360行目: | 393行目: | ||
else | else | ||
{ | { | ||
− | ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.sampleItemStacks[0]); | + | ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.inventory.sampleItemStacks[0]); |
if (itemstack == null) return false; | if (itemstack == null) return false; | ||
− | if (this.sampleItemStacks[2] == null) return true; | + | if (this.inventory.sampleItemStacks[2] == null) return true; |
− | if (!this.sampleItemStacks[2].isItemEqual(itemstack)) return false; | + | if (!this.inventory.sampleItemStacks[2].isItemEqual(itemstack)) return false; |
− | int result = this.sampleItemStacks[2].stackSize + itemstack.stackSize; | + | int result = this.inventory.sampleItemStacks[2].stackSize + itemstack.stackSize; |
− | return (result <= this.getInventoryStackLimit() && result <= itemstack.getMaxStackSize()); | + | return (result <= this.inventory.getInventoryStackLimit() && result <= itemstack.getMaxStackSize()); |
} | } | ||
} | } | ||
− | + | ||
//かまどの処理 | //かまどの処理 | ||
public void smeltItem() | public void smeltItem() | ||
374行目: | 407行目: | ||
if (this.canSmelt()) | if (this.canSmelt()) | ||
{ | { | ||
− | ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.sampleItemStacks[0]); | + | ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.inventory.sampleItemStacks[0]); |
− | + | ||
− | if (this.sampleItemStacks[2] == null) | + | if (this.inventory.sampleItemStacks[2] == null) |
{ | { | ||
− | this.sampleItemStacks[2] = itemstack.copy(); | + | this.inventory.sampleItemStacks[2] = itemstack.copy(); |
} | } | ||
− | else if (this.sampleItemStacks[2].isItemEqual(itemstack)) | + | else if (this.inventory.sampleItemStacks[2].isItemEqual(itemstack)) |
{ | { | ||
− | this.sampleItemStacks[2].stackSize += itemstack.stackSize; | + | this.inventory.sampleItemStacks[2].stackSize += itemstack.stackSize; |
} | } | ||
− | + | ||
− | --this.sampleItemStacks[0].stackSize; | + | --this.inventory.sampleItemStacks[0].stackSize; |
− | + | ||
− | if (this.sampleItemStacks[0].stackSize <= 0) | + | if (this.inventory.sampleItemStacks[0].stackSize <= 0) |
{ | { | ||
− | this.sampleItemStacks[0] = null; | + | this.inventory.sampleItemStacks[0] = null; |
} | } | ||
} | } | ||
} | } | ||
− | + | ||
//かまどの処理 | //かまどの処理 | ||
public static int getItemBurnTime(ItemStack par0ItemStack) | public static int getItemBurnTime(ItemStack par0ItemStack) | ||
405行目: | 438行目: | ||
int i = par0ItemStack.getItem().itemID; | int i = par0ItemStack.getItem().itemID; | ||
Item item = par0ItemStack.getItem(); | Item item = par0ItemStack.getItem(); | ||
− | + | ||
if (par0ItemStack.getItem() instanceof ItemBlock && Block.blocksList[i] != null) | if (par0ItemStack.getItem() instanceof ItemBlock && Block.blocksList[i] != null) | ||
{ | { | ||
Block block = Block.blocksList[i]; | Block block = Block.blocksList[i]; | ||
− | + | ||
if (block == Block.woodSingleSlab) | if (block == Block.woodSingleSlab) | ||
{ | { | ||
return 150; | return 150; | ||
} | } | ||
− | + | ||
if (block.blockMaterial == Material.wood) | if (block.blockMaterial == Material.wood) | ||
{ | { | ||
return 300; | return 300; | ||
} | } | ||
− | + | ||
− | if (block == Block. | + | if (block == Block.field_111034_cE) |
{ | { | ||
return 16000; | return 16000; | ||
} | } | ||
} | } | ||
− | + | ||
if (item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("WOOD")) return 200; | if (item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("WOOD")) return 200; | ||
if (item instanceof ItemSword && ((ItemSword) item).getToolMaterialName().equals("WOOD")) return 200; | if (item instanceof ItemSword && ((ItemSword) item).getToolMaterialName().equals("WOOD")) return 200; | ||
437行目: | 470行目: | ||
} | } | ||
} | } | ||
− | + | ||
//かまどの処理 | //かまどの処理 | ||
public static boolean isItemFuel(ItemStack par0ItemStack) | public static boolean isItemFuel(ItemStack par0ItemStack) | ||
{ | { | ||
return getItemBurnTime(par0ItemStack) > 0; | return getItemBurnTime(par0ItemStack) > 0; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | </source> | ||
+ | |||
+ | *InventorySample.java | ||
+ | <source lang = "java"> | ||
+ | package mods.tileentitysample; | ||
+ | |||
+ | import net.minecraft.entity.player.EntityPlayer; | ||
+ | import net.minecraft.inventory.ISidedInventory; | ||
+ | import net.minecraft.item.Item; | ||
+ | import net.minecraft.item.ItemStack; | ||
+ | |||
+ | public class InventorySample implements ISidedInventory { | ||
+ | |||
+ | private static final int[] slots_top = new int[] {0}; | ||
+ | private static final int[] slots_bottom = new int[] {2, 1}; | ||
+ | private static final int[] slots_sides = new int[] {1}; | ||
+ | |||
+ | public ItemStack[] sampleItemStacks = new ItemStack[3]; | ||
+ | |||
+ | private TileEntitySample tileentity; | ||
+ | |||
+ | public InventorySample(TileEntitySample tileentity) { | ||
+ | this.tileentity = tileentity; | ||
} | } | ||
449行目: | 509行目: | ||
return this.sampleItemStacks.length; | return this.sampleItemStacks.length; | ||
} | } | ||
− | + | ||
// インベントリ内の任意のスロットにあるアイテムを取得 | // インベントリ内の任意のスロットにあるアイテムを取得 | ||
@Override | @Override | ||
455行目: | 515行目: | ||
return this.sampleItemStacks[par1]; | return this.sampleItemStacks[par1]; | ||
} | } | ||
− | + | ||
@Override | @Override | ||
public ItemStack decrStackSize(int par1, int par2) { | public ItemStack decrStackSize(int par1, int par2) { | ||
461行目: | 521行目: | ||
{ | { | ||
ItemStack itemstack; | ItemStack itemstack; | ||
− | + | ||
if (this.sampleItemStacks[par1].stackSize <= par2) | if (this.sampleItemStacks[par1].stackSize <= par2) | ||
{ | { | ||
471行目: | 531行目: | ||
{ | { | ||
itemstack = this.sampleItemStacks[par1].splitStack(par2); | itemstack = this.sampleItemStacks[par1].splitStack(par2); | ||
− | + | ||
if (this.sampleItemStacks[par1].stackSize == 0) | if (this.sampleItemStacks[par1].stackSize == 0) | ||
{ | { | ||
this.sampleItemStacks[par1] = null; | this.sampleItemStacks[par1] = null; | ||
} | } | ||
− | + | ||
return itemstack; | return itemstack; | ||
} | } | ||
485行目: | 545行目: | ||
} | } | ||
} | } | ||
− | + | ||
@Override | @Override | ||
public ItemStack getStackInSlotOnClosing(int par1) { | public ItemStack getStackInSlotOnClosing(int par1) { | ||
499行目: | 559行目: | ||
} | } | ||
} | } | ||
− | + | ||
// インベントリ内のスロットにアイテムを入れる | // インベントリ内のスロットにアイテムを入れる | ||
@Override | @Override | ||
public void setInventorySlotContents(int par1, ItemStack par2ItemStack) { | public void setInventorySlotContents(int par1, ItemStack par2ItemStack) { | ||
this.sampleItemStacks[par1] = par2ItemStack; | this.sampleItemStacks[par1] = par2ItemStack; | ||
− | + | ||
if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) | if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) | ||
{ | { | ||
510行目: | 570行目: | ||
} | } | ||
} | } | ||
− | + | ||
// インベントリの名前 | // インベントリの名前 | ||
@Override | @Override | ||
516行目: | 576行目: | ||
return "Sample"; | return "Sample"; | ||
} | } | ||
− | + | ||
// 多言語対応かどうか | // 多言語対応かどうか | ||
@Override | @Override | ||
522行目: | 582行目: | ||
return false; | return false; | ||
} | } | ||
− | + | ||
// インベントリ内のスタック限界値 | // インベントリ内のスタック限界値 | ||
@Override | @Override | ||
528行目: | 588行目: | ||
return 64; | return 64; | ||
} | } | ||
− | + | ||
@Override | @Override | ||
public void onInventoryChanged() { | public void onInventoryChanged() { | ||
− | this.onInventoryChanged(); | + | this.tileentity.onInventoryChanged(); |
} | } | ||
− | + | ||
// par1EntityPlayerがTileEntityを使えるかどうか | // par1EntityPlayerがTileEntityを使えるかどうか | ||
@Override | @Override | ||
public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) { | public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) { | ||
− | return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D; | + | return this.tileentity.worldObj.getBlockTileEntity(this.tileentity.xCoord, this.tileentity.yCoord, this.tileentity.zCoord) != this.tileentity ? false : par1EntityPlayer.getDistanceSq((double) this.tileentity.xCoord + 0.5D, (double) this.tileentity.yCoord + 0.5D, (double) this.tileentity.zCoord + 0.5D) <= 64.0D; |
} | } | ||
− | + | ||
@Override | @Override | ||
public void openChest() {} | public void openChest() {} | ||
− | + | ||
@Override | @Override | ||
public void closeChest() {} | public void closeChest() {} | ||
− | + | ||
@Override | @Override | ||
public boolean isItemValidForSlot(int par1, ItemStack par2ItemStack) { | public boolean isItemValidForSlot(int par1, ItemStack par2ItemStack) { | ||
− | return par1 == 2 ? false : (par1 == 1 ? this.isItemFuel(par2ItemStack) : true); | + | return par1 == 2 ? false : (par1 == 1 ? this.tileentity.isItemFuel(par2ItemStack) : true); |
} | } | ||
− | + | ||
//ホッパーにアイテムの受け渡しをする際の優先度 | //ホッパーにアイテムの受け渡しをする際の優先度 | ||
@Override | @Override | ||
556行目: | 616行目: | ||
return par1 == 0 ? slots_bottom : (par1 == 1 ? slots_top : slots_sides); | return par1 == 0 ? slots_bottom : (par1 == 1 ? slots_top : slots_sides); | ||
} | } | ||
− | + | ||
//ホッパーからアイテムを入れられるかどうか | //ホッパーからアイテムを入れられるかどうか | ||
@Override | @Override | ||
562行目: | 622行目: | ||
return this.isItemValidForSlot(par1, par2ItemStack); | return this.isItemValidForSlot(par1, par2ItemStack); | ||
} | } | ||
− | + | ||
//隣接するホッパーにアイテムを送れるかどうか | //隣接するホッパーにアイテムを送れるかどうか | ||
@Override | @Override | ||
568行目: | 628行目: | ||
return par3 != 0 || par1 != 1 || par2ItemStack.itemID == Item.bucketEmpty.itemID; | return par3 != 0 || par1 != 1 || par2ItemStack.itemID == Item.bucketEmpty.itemID; | ||
} | } | ||
+ | |||
} | } | ||
574行目: | 635行目: | ||
*ContainerSample.java | *ContainerSample.java | ||
<source lang = "java"> | <source lang = "java"> | ||
− | package mods. | + | package mods.tileentitysample; |
− | + | ||
import net.minecraft.entity.player.EntityPlayer; | import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.inventory.Container; | import net.minecraft.inventory.Container; | ||
586行目: | 647行目: | ||
import cpw.mods.fml.relauncher.Side; | import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | import cpw.mods.fml.relauncher.SideOnly; | ||
− | + | ||
public class ContainerSample extends Container { | public class ContainerSample extends Container { | ||
− | + | ||
private TileEntitySample tileentity; | private TileEntitySample tileentity; | ||
− | + | ||
+ | private InventorySample inventory; | ||
+ | |||
private int lastCookTime; | private int lastCookTime; | ||
private int lastBurnTime; | private int lastBurnTime; | ||
private int lastItemBurnTime; | private int lastItemBurnTime; | ||
− | + | ||
public ContainerSample(EntityPlayer player, TileEntitySample par2TileEntity) { | public ContainerSample(EntityPlayer player, TileEntitySample par2TileEntity) { | ||
this.tileentity = par2TileEntity; | this.tileentity = par2TileEntity; | ||
− | + | this.inventory = par2TileEntity.inventory; | |
+ | |||
// InventorySampleで追加するインベントリ | // InventorySampleで追加するインベントリ | ||
− | this.addSlotToContainer(new Slot(this. | + | this.addSlotToContainer(new Slot(this.inventory, 0, 56, 17)); |
− | this.addSlotToContainer(new Slot(this. | + | this.addSlotToContainer(new Slot(this.inventory, 1, 56, 53)); |
− | this.addSlotToContainer(new SlotFurnace(player, this. | + | this.addSlotToContainer(new SlotFurnace(player, this.inventory, 2, 116, 35)); |
int i; | int i; | ||
− | + | ||
// 1 ~ 3段目のインベントリ | // 1 ~ 3段目のインベントリ | ||
for (i = 0; i < 3; ++i) | for (i = 0; i < 3; ++i) | ||
612行目: | 676行目: | ||
} | } | ||
} | } | ||
− | + | ||
// 4段目のインベントリ | // 4段目のインベントリ | ||
for (i = 0; i < 9; ++i) | for (i = 0; i < 9; ++i) | ||
619行目: | 683行目: | ||
} | } | ||
} | } | ||
− | + | ||
public void addCraftingToCrafters(ICrafting par1ICrafting) | public void addCraftingToCrafters(ICrafting par1ICrafting) | ||
{ | { | ||
627行目: | 691行目: | ||
par1ICrafting.sendProgressBarUpdate(this, 2, this.tileentity.currentItemBurnTime); | par1ICrafting.sendProgressBarUpdate(this, 2, this.tileentity.currentItemBurnTime); | ||
} | } | ||
− | + | ||
// 更新を送る | // 更新を送る | ||
public void detectAndSendChanges() | public void detectAndSendChanges() | ||
{ | { | ||
super.detectAndSendChanges(); | super.detectAndSendChanges(); | ||
− | + | ||
for (int i = 0; i < this.crafters.size(); ++i) | for (int i = 0; i < this.crafters.size(); ++i) | ||
{ | { | ||
ICrafting icrafting = (ICrafting)this.crafters.get(i); | ICrafting icrafting = (ICrafting)this.crafters.get(i); | ||
− | + | ||
if (this.lastCookTime != this.tileentity.cookTime) | if (this.lastCookTime != this.tileentity.cookTime) | ||
{ | { | ||
icrafting.sendProgressBarUpdate(this, 0, this.tileentity.cookTime); | icrafting.sendProgressBarUpdate(this, 0, this.tileentity.cookTime); | ||
} | } | ||
− | + | ||
if (this.lastBurnTime != this.tileentity.burnTime) | if (this.lastBurnTime != this.tileentity.burnTime) | ||
{ | { | ||
icrafting.sendProgressBarUpdate(this, 1, this.tileentity.burnTime); | icrafting.sendProgressBarUpdate(this, 1, this.tileentity.burnTime); | ||
} | } | ||
− | + | ||
if (this.lastItemBurnTime != this.tileentity.currentItemBurnTime) | if (this.lastItemBurnTime != this.tileentity.currentItemBurnTime) | ||
{ | { | ||
652行目: | 716行目: | ||
} | } | ||
} | } | ||
− | + | ||
this.lastCookTime = this.tileentity.cookTime; | this.lastCookTime = this.tileentity.cookTime; | ||
this.lastBurnTime = this.tileentity.burnTime; | this.lastBurnTime = this.tileentity.burnTime; | ||
this.lastItemBurnTime = this.tileentity.currentItemBurnTime; | this.lastItemBurnTime = this.tileentity.currentItemBurnTime; | ||
} | } | ||
− | + | ||
// 更新する | // 更新する | ||
@SideOnly(Side.CLIENT) | @SideOnly(Side.CLIENT) | ||
666行目: | 730行目: | ||
this.tileentity.cookTime = par2; | this.tileentity.cookTime = par2; | ||
} | } | ||
− | + | ||
if (par1 == 1) | if (par1 == 1) | ||
{ | { | ||
this.tileentity.burnTime = par2; | this.tileentity.burnTime = par2; | ||
} | } | ||
− | + | ||
if (par1 == 2) | if (par1 == 2) | ||
{ | { | ||
677行目: | 741行目: | ||
} | } | ||
} | } | ||
− | + | ||
// InventorySample内のisUseableByPlayerメソッドを参照 | // InventorySample内のisUseableByPlayerメソッドを参照 | ||
@Override | @Override | ||
public boolean canInteractWith(EntityPlayer par1EntityPlayer) { | public boolean canInteractWith(EntityPlayer par1EntityPlayer) { | ||
− | return this. | + | return this.inventory.isUseableByPlayer(par1EntityPlayer); |
} | } | ||
− | + | ||
// Shiftクリック | // Shiftクリック | ||
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) | public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) | ||
689行目: | 753行目: | ||
ItemStack itemstack = null; | ItemStack itemstack = null; | ||
Slot slot = (Slot)this.inventorySlots.get(par2); | Slot slot = (Slot)this.inventorySlots.get(par2); | ||
− | + | ||
if (slot != null && slot.getHasStack()) | if (slot != null && slot.getHasStack()) | ||
{ | { | ||
ItemStack itemstack1 = slot.getStack(); | ItemStack itemstack1 = slot.getStack(); | ||
itemstack = itemstack1.copy(); | itemstack = itemstack1.copy(); | ||
− | + | ||
//スロット番号が2の時 | //スロット番号が2の時 | ||
if (par2 == 2) | if (par2 == 2) | ||
703行目: | 767行目: | ||
return null; | return null; | ||
} | } | ||
− | + | ||
slot.onSlotChange(itemstack1, itemstack); | slot.onSlotChange(itemstack1, itemstack); | ||
} | } | ||
743行目: | 807行目: | ||
return null; | return null; | ||
} | } | ||
− | + | ||
if (itemstack1.stackSize == 0) | if (itemstack1.stackSize == 0) | ||
{ | { | ||
752行目: | 816行目: | ||
slot.onSlotChanged(); | slot.onSlotChanged(); | ||
} | } | ||
− | + | ||
if (itemstack1.stackSize == itemstack.stackSize) | if (itemstack1.stackSize == itemstack.stackSize) | ||
{ | { | ||
return null; | return null; | ||
} | } | ||
− | + | ||
slot.onPickupFromSlot(par1EntityPlayer, itemstack1); | slot.onPickupFromSlot(par1EntityPlayer, itemstack1); | ||
} | } | ||
− | + | ||
return itemstack; | return itemstack; | ||
} | } | ||
− | + | ||
} | } | ||
770行目: | 834行目: | ||
*GuiSample.java | *GuiSample.java | ||
<source lang = "java"> | <source lang = "java"> | ||
− | package mods. | + | package mods.tileentitysample; |
− | + | ||
import net.minecraft.client.gui.inventory.GuiContainer; | import net.minecraft.client.gui.inventory.GuiContainer; | ||
+ | import net.minecraft.client.resources.I18n; | ||
import net.minecraft.entity.player.EntityPlayer; | import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.util.ResourceLocation; | import net.minecraft.util.ResourceLocation; | ||
− | |||
import org.lwjgl.opengl.GL11; | import org.lwjgl.opengl.GL11; | ||
− | + | ||
public class GuiSample extends GuiContainer { | public class GuiSample extends GuiContainer { | ||
− | + | ||
private TileEntitySample tileentity; | private TileEntitySample tileentity; | ||
− | + | private InventorySample inventory; | |
− | + | ||
− | private | ||
− | |||
public GuiSample(EntityPlayer player, TileEntitySample par2TileEntity) { | public GuiSample(EntityPlayer player, TileEntitySample par2TileEntity) { | ||
super(new ContainerSample(player, par2TileEntity)); | super(new ContainerSample(player, par2TileEntity)); | ||
this.tileentity = par2TileEntity; | this.tileentity = par2TileEntity; | ||
+ | this.inventory = par2TileEntity.inventory; | ||
} | } | ||
− | + | ||
@Override | @Override | ||
protected void drawGuiContainerForegroundLayer(int par1, int par2) | protected void drawGuiContainerForegroundLayer(int par1, int par2) | ||
{ | { | ||
//インベントリ名の描画 | //インベントリ名の描画 | ||
− | String s = this. | + | String s = this.inventory.isInvNameLocalized() ? this.inventory.getInvName() : I18n.func_135053_a(this.inventory.getInvName()); |
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752); | this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752); | ||
− | this.fontRenderer.drawString( | + | this.fontRenderer.drawString(I18n.func_135053_a("container.inventory"), 8, this.ySize - 96 + 2, 4210752); |
} | } | ||
− | + | ||
@Override | @Override | ||
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) | protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) | ||
{ | { | ||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); | GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); | ||
− | + | ||
//テクスチャの指定 | //テクスチャの指定 | ||
− | this.mc.getTextureManager().bindTexture( | + | //ResourceLocationの第一引数を付け足してドメインを指定することもできる |
− | + | //例:new ResourceLocation("sample", "textures/gui/container/furnace.png") | |
+ | this.mc.getTextureManager().bindTexture(new ResourceLocation("textures/gui/container/furnace.png")); | ||
+ | |||
//かまど描画処理 | //かまど描画処理 | ||
int k = (this.width - this.xSize) / 2; | int k = (this.width - this.xSize) / 2; | ||
813行目: | 878行目: | ||
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); | this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); | ||
int i1; | int i1; | ||
− | + | ||
if (this.tileentity.isBurning()) | if (this.tileentity.isBurning()) | ||
{ | { | ||
819行目: | 884行目: | ||
this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 2); | this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 2); | ||
} | } | ||
− | + | ||
i1 = this.tileentity.getCookProgressScaled(24); | i1 = this.tileentity.getCookProgressScaled(24); | ||
this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16); | this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16); | ||
} | } | ||
− | + | ||
} | } | ||
830行目: | 895行目: | ||
*GuiHandler.java | *GuiHandler.java | ||
<source lang = "java"> | <source lang = "java"> | ||
− | package mods. | + | package mods.tileentitysample; |
− | + | ||
import net.minecraft.entity.player.EntityPlayer; | import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.tileentity.TileEntity; | import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.world.World; | import net.minecraft.world.World; | ||
import cpw.mods.fml.common.network.IGuiHandler; | import cpw.mods.fml.common.network.IGuiHandler; | ||
− | + | ||
public class GuiHandler implements IGuiHandler { | public class GuiHandler implements IGuiHandler { | ||
− | + | ||
@Override | @Override | ||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { | public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { | ||
if (!world.blockExists(x, y, z)) | if (!world.blockExists(x, y, z)) | ||
return null; | return null; | ||
− | + | ||
TileEntity tileentity = world.getBlockTileEntity(x, y, z); | TileEntity tileentity = world.getBlockTileEntity(x, y, z); | ||
if (tileentity instanceof TileEntitySample) { | if (tileentity instanceof TileEntitySample) { | ||
850行目: | 915行目: | ||
return null; | return null; | ||
} | } | ||
− | + | ||
@Override | @Override | ||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { | public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { | ||
if (!world.blockExists(x, y, z)) | if (!world.blockExists(x, y, z)) | ||
return null; | return null; | ||
− | + | ||
TileEntity tileentity = world.getBlockTileEntity(x, y, z); | TileEntity tileentity = world.getBlockTileEntity(x, y, z); | ||
if (tileentity instanceof TileEntitySample) { | if (tileentity instanceof TileEntitySample) { | ||
862行目: | 927行目: | ||
return null; | return null; | ||
} | } | ||
− | + | ||
+ | } | ||
+ | |||
+ | </source> | ||
+ | |||
+ | *PacketHandler.java | ||
+ | <source lang = "java"> | ||
+ | package mods.tileentitysample; | ||
+ | |||
+ | import java.io.ByteArrayOutputStream; | ||
+ | import java.io.DataOutputStream; | ||
+ | |||
+ | import net.minecraft.entity.player.EntityPlayer; | ||
+ | import net.minecraft.network.INetworkManager; | ||
+ | import net.minecraft.network.packet.Packet; | ||
+ | import net.minecraft.network.packet.Packet250CustomPayload; | ||
+ | import net.minecraft.tileentity.TileEntity; | ||
+ | import net.minecraft.world.World; | ||
+ | |||
+ | import com.google.common.io.ByteArrayDataInput; | ||
+ | import com.google.common.io.ByteStreams; | ||
+ | |||
+ | import cpw.mods.fml.client.FMLClientHandler; | ||
+ | import cpw.mods.fml.common.network.IPacketHandler; | ||
+ | import cpw.mods.fml.common.network.Player; | ||
+ | |||
+ | public class PacketHandler implements IPacketHandler { | ||
+ | |||
+ | @Override | ||
+ | public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) | ||
+ | { | ||
+ | if (packet.channel.equals("updateTile")) { | ||
+ | ByteArrayDataInput data = ByteStreams.newDataInput(packet.data); | ||
+ | |||
+ | int x = data.readInt(); | ||
+ | int y = data.readInt(); | ||
+ | int z = data.readInt(); | ||
+ | |||
+ | TileEntity tileentity = null; | ||
+ | |||
+ | World worldClient = FMLClientHandler.instance().getClient().theWorld; | ||
+ | World worldServer = ((EntityPlayer) player).worldObj; | ||
+ | |||
+ | if (worldClient != null && worldServer == null) | ||
+ | { | ||
+ | tileentity = worldClient.getBlockTileEntity(x, y, z); | ||
+ | } | ||
+ | |||
+ | if (worldServer != null) | ||
+ | { | ||
+ | tileentity = worldServer.getBlockTileEntity(x, y, z); | ||
+ | } | ||
+ | |||
+ | if (tileentity != null) | ||
+ | { | ||
+ | if (tileentity instanceof TileEntityBlueFurnace) | ||
+ | { | ||
+ | ((TileEntityBlueFurnace) tileentity).readToPacket(data); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | public static Packet getPacket(TileEntityBlueFurnace tileentity) | ||
+ | { | ||
+ | ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
+ | DataOutputStream dos = new DataOutputStream(bos); | ||
+ | |||
+ | int x = tileentity.xCoord; | ||
+ | int y = tileentity.yCoord; | ||
+ | int z = tileentity.zCoord; | ||
+ | |||
+ | try | ||
+ | { | ||
+ | dos.writeInt(x); | ||
+ | dos.writeInt(y); | ||
+ | dos.writeInt(z); | ||
+ | |||
+ | tileentity.writeToPacket(dos); | ||
+ | } | ||
+ | catch (Exception e) | ||
+ | { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | |||
+ | Packet250CustomPayload packet = new Packet250CustomPayload(); | ||
+ | |||
+ | packet.channel = "updateTile"; | ||
+ | packet.data = bos.toByteArray(); | ||
+ | packet.length = bos.size(); | ||
+ | packet.isChunkDataPacket = true; | ||
+ | |||
+ | return packet; | ||
+ | } | ||
+ | |||
+ | public static Packet getPacket(TileEntityRedFurnace tileentity) | ||
+ | { | ||
+ | ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
+ | DataOutputStream dos = new DataOutputStream(bos); | ||
+ | |||
+ | int x = tileentity.xCoord; | ||
+ | int y = tileentity.yCoord; | ||
+ | int z = tileentity.zCoord; | ||
+ | |||
+ | try | ||
+ | { | ||
+ | dos.writeInt(x); | ||
+ | dos.writeInt(y); | ||
+ | dos.writeInt(z); | ||
+ | |||
+ | tileentity.writeToPacket(dos); | ||
+ | } | ||
+ | catch (Exception e) | ||
+ | { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | |||
+ | Packet250CustomPayload packet = new Packet250CustomPayload(); | ||
+ | |||
+ | packet.channel = "updateTile"; | ||
+ | packet.data = bos.toByteArray(); | ||
+ | packet.length = bos.size(); | ||
+ | packet.isChunkDataPacket = true; | ||
+ | |||
+ | return packet; | ||
+ | } | ||
+ | |||
} | } | ||
905行目: | 1,096行目: | ||
<source lang = "java"> | <source lang = "java"> | ||
− | + | public void readToPacket(ByteArrayDataInput data) { | |
− | + | ~ 中略 ~ | |
− | + | } | |
− | + | ||
− | + | public void writeToPacket(DataOutputStream dos) { | |
− | } | + | ~ 中略 ~ |
− | + | } | |
− | + | ||
− | + | @Override | |
− | + | public Packet getDescriptionPacket() | |
− | + | { | |
+ | //パケットの取得 | ||
+ | return PacketHandler.getPacket(this); | ||
+ | } | ||
</source> | </source> | ||
NBTに保存した情報をパケットで飛ばすことができる。 | NBTに保存した情報をパケットで飛ばすことができる。 |