Created
July 10, 2014 14:11
-
-
Save MultiMote/dee9b07369fa4ca40336 to your computer and use it in GitHub Desktop.
Schematic builder item
This file contains 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 com.multi.microZ.item.admin; | |
import com.multi.microZ.Core; | |
import com.multi.microZ.handlers.OtherHandlers; | |
import com.multi.microZ.item.admin.AdminItem; | |
import com.multi.microZ.utils.OtherUtils; | |
import com.multi.microZ.utils.SchemUtils; | |
import net.minecraft.block.Block; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.init.Blocks; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.tileentity.TileEntity; | |
import net.minecraft.util.ChatComponentText; | |
import net.minecraft.util.EnumChatFormatting; | |
import net.minecraft.world.World; | |
import java.util.List; | |
/** | |
* Created by multimote on 05.07.14. | |
*/ | |
public class BuilderItem extends AdminItem { | |
private String schematic; | |
private int ylevel; | |
private int xShift; | |
private boolean logBuilding; | |
private SchemUtils sut; | |
public BuilderItem(String schematic, int ylevel, int xShift, boolean logBuilding){ | |
setUnlocalizedName("test builder"); | |
this.schematic = schematic; | |
this.ylevel = ylevel; | |
this.xShift = xShift; | |
this.logBuilding = logBuilding; | |
this.setCreativeTab(Core.dayztab_builders); | |
sut = new SchemUtils(); | |
} | |
public int getYlevel(){ | |
return ylevel; | |
} | |
public int getxShift(){ | |
return xShift; | |
} | |
public String getSchematicName(){ | |
return schematic; | |
} | |
public void onUpdate(ItemStack is, World w, Entity ent, int par4, boolean par5){ | |
super.onUpdate(is, w, ent, par4, par5); | |
checkCompound(is); | |
if(getIntIfNotNull(is, "delay")>0)decrementIntIfNotNull(is, "delay"); | |
} | |
public boolean onItemUse(ItemStack is, EntityPlayer placer, World world, int x, int y, int z, int side, float px, float py, float pz) { | |
if(!world.isRemote && !getBoolIfNotNull(is, "blocked") && getIntIfNotNull(is, "delay")<=0 && side == 1 && OtherUtils.checkPermsAndSendMsg(placer)){ | |
setBoolIfNotNull(is, "blocked", true); | |
setIntIfNotNull(is, "delay", 20); | |
int rotation = OtherUtils.getPlayerRotationSide(placer); | |
SchemUtils.Schematic sh = sut.get(schematic); | |
if(sh==null){ | |
placer.addChatMessage(new ChatComponentText("Schematic is ded!")); | |
world.playSoundAtEntity(placer, "microz:other.ded", 0.5F, 1.0F); | |
//this.setUnlocalizedName("builder_corrupt"); | |
setBoolIfNotNull(is, "corrupt", true); | |
return false; | |
} | |
if(logBuilding)placer.addChatMessage(new ChatComponentText("Building started.")); | |
int i = 0; | |
for(int sy = 0; sy < sh.height; sy++) | |
for(int sz = 0; sz < sh.length; sz++) | |
for(int sx = 0; sx < sh.width; sx++){ | |
Block b = Block.getBlockById(sh.blocks[i]); | |
if(b!= Blocks.air) | |
{ | |
int rx = sut.blockCoordsRotation(sx - this.getxShift(), sz, rotation)[0]; | |
int rz = sut.blockCoordsRotation(sx - this.getxShift(), sz, rotation)[1]; | |
world.setBlockToAir(x + rx, y + ylevel + sy, z + rz); | |
world.setBlock(x+rx, y+ylevel+sy, z+rz, b, sut.rotateMeta(sh.blocks[i], sh.data[i], rotation), 2); | |
} | |
i++; | |
} | |
if (sh.tileentities != null) | |
{ | |
for (int i1 = 0; i1 < sh.tileentities.tagCount(); ++i1) | |
{ | |
NBTTagCompound nbttagcompound4 = sh.tileentities.getCompoundTagAt(i1); | |
TileEntity tileentity = TileEntity.createAndLoadEntity(nbttagcompound4); | |
if (tileentity != null) | |
{ | |
int[] conv2 = sut.blockCoordsRotation(tileentity.xCoord - this.getxShift(), tileentity.zCoord, rotation); | |
tileentity.xCoord = x + conv2[0]; | |
tileentity.yCoord += y+ylevel; | |
tileentity.zCoord = z + conv2[1]; | |
world.setTileEntity(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord, tileentity); | |
} | |
} | |
} | |
if(logBuilding) placer.addChatMessage(new ChatComponentText("Building finished.")); | |
setBoolIfNotNull(is, "blocked", false); | |
return true; | |
} | |
return false; | |
} | |
@Override | |
public void addInformation(ItemStack is, EntityPlayer p, List list, boolean par4) { | |
super.addInformation(is, p, list, par4); | |
if(getBoolIfNotNull(is, "blocked") || getIntIfNotNull(is, "delay")>0) | |
{ | |
if(getBoolIfNotNull(is, "corrupt")) | |
list.add(EnumChatFormatting.RED + "Blocked and corrupt"); | |
else | |
list.add(EnumChatFormatting.GOLD + "Blocked"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment