Finaly, first model render of Defender
This commit is contained in:
parent
71e86f31ac
commit
c7d08045d8
@ -12,7 +12,11 @@ import fr.jackcartersmith.orbsat.OrbitalSatellite;
|
||||
import fr.jackcartersmith.orbsat.client.handler.ClientEventHandler;
|
||||
import fr.jackcartersmith.orbsat.client.handler.ParticleHandler;
|
||||
import fr.jackcartersmith.orbsat.client.handler.ResourceHandler;
|
||||
import fr.jackcartersmith.orbsat.client.render.block.RenderDefender;
|
||||
import fr.jackcartersmith.orbsat.client.render.tile.RenderTileDefender;
|
||||
import fr.jackcartersmith.orbsat.common.CommonProxy;
|
||||
import fr.jackcartersmith.orbsat.common.OSBlocks;
|
||||
import fr.jackcartersmith.orbsat.common.tileentities.TileDefender;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.ISound;
|
||||
import net.minecraft.client.particle.EntityFX;
|
||||
@ -53,6 +57,12 @@ public class ClientProxy extends CommonProxy {
|
||||
}
|
||||
|
||||
public void registerRendering() {
|
||||
//Item Renderers
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(OSBlocks.defender), new RenderDefender());
|
||||
|
||||
//TileEntitySpecialRenderers
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileDefender.class, new RenderTileDefender());
|
||||
|
||||
/*
|
||||
//Item Renderers
|
||||
MinecraftForgeClient.registerItemRenderer(ModItems.wyvernBow, new RenderBow());
|
||||
|
@ -0,0 +1,106 @@
|
||||
package fr.jackcartersmith.orbsat.client.model;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
public class ModelDefender extends ModelBase {
|
||||
public ModelRenderer Shape1;
|
||||
public ModelRenderer Shape2;
|
||||
public ModelRenderer Shape3;
|
||||
public ModelRenderer Shape4;
|
||||
public ModelRenderer Shape5;
|
||||
public ModelRenderer Shape6;
|
||||
public ModelRenderer Shape7;
|
||||
public ModelRenderer Shape8;
|
||||
|
||||
public ModelDefender()
|
||||
{
|
||||
this.textureWidth = 128;
|
||||
this.textureHeight = 128;
|
||||
this.Shape1 = new ModelRenderer(this, 0, 0);
|
||||
this.Shape1.addBox(-8.0F, 0.0F, -8.0F, 16, 1, 16);
|
||||
this.Shape1.setRotationPoint(0.0F, 23.0F, 0.0F);
|
||||
this.Shape1.setTextureSize(128, 128);
|
||||
this.Shape1.mirror = true;
|
||||
this.setRotateAngle(this.Shape1, 0.0F, 0.0F, 0.0F);
|
||||
this.Shape2 = new ModelRenderer(this, 64, 0);
|
||||
this.Shape2.addBox(0.0F, 0.0F, -4.0F, 1, 7, 8);
|
||||
this.Shape2.setRotationPoint(0.0F, 16.0F, -7.0F);
|
||||
this.Shape2.setTextureSize(128, 128);
|
||||
this.Shape2.mirror = true;
|
||||
this.setRotateAngle(this.Shape2, 0.0F, ((float)Math.PI / 2F), 0.0F);
|
||||
this.Shape3 = new ModelRenderer(this, 64, 0);
|
||||
this.Shape3.addBox(0.0F, 0.0F, -4.0F, 1, 7, 8);
|
||||
this.Shape3.setRotationPoint(-7.0F, 16.0F, 0.0F);
|
||||
this.Shape3.setTextureSize(128, 128);
|
||||
this.Shape3.mirror = true;
|
||||
this.setRotateAngle(this.Shape3, 0.0F, (float)Math.PI, 0.0F);
|
||||
this.Shape4 = new ModelRenderer(this, 64, 0);
|
||||
this.Shape4.addBox(0.0F, 0.0F, -4.0F, 1, 7, 8);
|
||||
this.Shape4.setRotationPoint(0.0F, 16.0F, 7.0F);
|
||||
this.Shape4.setTextureSize(128, 128);
|
||||
this.Shape4.mirror = true;
|
||||
this.setRotateAngle(this.Shape4, 0.0F, -((float)Math.PI / 2F), 0.0F);
|
||||
this.Shape5 = new ModelRenderer(this, 64, 0);
|
||||
this.Shape5.addBox(0.0F, 0.0F, -4.0F, 1, 7, 8);
|
||||
this.Shape5.setRotationPoint(7.0F, 16.0F, 0.0F);
|
||||
this.Shape5.setTextureSize(128, 128);
|
||||
this.Shape5.mirror = true;
|
||||
this.setRotateAngle(this.Shape5, 0.0F, 0.0F, 0.0F);
|
||||
this.Shape6 = new ModelRenderer(this, 0, 21);
|
||||
this.Shape6.addBox(-1.0F, 0.0F, -1.0F, 2, 22, 2);
|
||||
this.Shape6.setRotationPoint(0.0F, 0.0F, 0.0F);
|
||||
this.Shape6.setTextureSize(128, 128);
|
||||
this.Shape6.mirror = true;
|
||||
this.setRotateAngle(this.Shape6, 0.0F, 0.0F, 0.0F);
|
||||
this.Shape7 = new ModelRenderer(this, 85, 0);
|
||||
this.Shape7.addBox(-3.0F, -3.0F, -3.0F, 6, 6, 6);
|
||||
this.Shape7.setRotationPoint(0.0F, -3.0F, 0.0F);
|
||||
this.Shape7.setTextureSize(128, 128);
|
||||
this.Shape7.mirror = true;
|
||||
this.setRotateAngle(this.Shape7, ((float)Math.PI / 4F), 0.0F, ((float)Math.PI / 4F));
|
||||
this.Shape8 = new ModelRenderer(this, 10, 26);
|
||||
this.Shape8.addBox(-3.0F, 0.0F, -3.0F, 6, 2, 6);
|
||||
this.Shape8.setRotationPoint(0.0F, 20.0F, 0.0F);
|
||||
this.Shape8.setTextureSize(128, 128);
|
||||
this.Shape8.mirror = true;
|
||||
this.setRotateAngle(this.Shape8, 0.0F, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Entity entity, float embitterRotation, float brightness, float x, float y, float z, float scale) {
|
||||
this.Shape1.render(scale);
|
||||
this.Shape2.render(scale);
|
||||
this.Shape3.render(scale);
|
||||
this.Shape4.render(scale);
|
||||
this.Shape5.render(scale);
|
||||
this.Shape6.render(scale);
|
||||
this.Shape8.render(scale);
|
||||
|
||||
float lastBrightnessX = OpenGlHelper.lastBrightnessX;
|
||||
float lastBrightnessY = OpenGlHelper.lastBrightnessY;
|
||||
|
||||
float b = brightness * 200F;
|
||||
float colour = Math.min(2F, (brightness * 2F) + 0.5F);
|
||||
if (brightness > 0F) GL11.glDisable(GL11.GL_LIGHTING);
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, Math.min(200F, lastBrightnessX + b), Math.min(200F, lastBrightnessY + b));
|
||||
GL11.glColor4f(colour, colour, colour, 1F);
|
||||
this.Shape7.render(scale);
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lastBrightnessX, lastBrightnessY);
|
||||
if (brightness > 0F) GL11.glEnable(GL11.GL_LIGHTING);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a helper function from Tabula to set the rotation of model parts
|
||||
*/
|
||||
public void setRotateAngle(ModelRenderer modelRenderer, float x, float y, float z) {
|
||||
modelRenderer.rotateAngleX = x;
|
||||
modelRenderer.rotateAngleY = y;
|
||||
modelRenderer.rotateAngleZ = z;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package fr.jackcartersmith.orbsat.client.render.block;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import fr.jackcartersmith.orbsat.client.handler.ResourceHandler;
|
||||
import fr.jackcartersmith.orbsat.client.render.tile.RenderTileDefender;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
|
||||
public class RenderDefender implements IItemRenderer{
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
|
||||
GL11.glPushMatrix();
|
||||
float scale = (1F / 16F);
|
||||
|
||||
if (type == ItemRenderType.INVENTORY) {
|
||||
GL11.glScaled(0.76, 0.76, 0.76);
|
||||
GL11.glTranslated(0.5, 1.0, 0.5);
|
||||
GL11.glRotated(180, 0, 1, 0);
|
||||
} else if (type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON) {
|
||||
GL11.glTranslated(0.5, 2, 0.5);
|
||||
GL11.glRotated(90, 0, 1, 0);
|
||||
} else if (type == ItemRenderType.ENTITY) {
|
||||
GL11.glScaled(3.0, 3.0, 3.0);
|
||||
GL11.glTranslated(0.0, 1.5, 0.0);
|
||||
GL11.glRotated(180, 0, 1, 0);
|
||||
}
|
||||
GL11.glRotated(180, 0, 0, 1);
|
||||
|
||||
ResourceHandler.bindResource("textures/models/defender.png");
|
||||
RenderTileDefender.modelDefender.render(null, 1F, 0F, 0F, 0F, 0F, scale);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package fr.jackcartersmith.orbsat.client.render.tile;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import fr.jackcartersmith.orbsat.client.handler.ResourceHandler;
|
||||
import fr.jackcartersmith.orbsat.client.model.ModelDefender;
|
||||
import fr.jackcartersmith.orbsat.common.tileentities.TileDefender;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class RenderTileDefender extends TileEntitySpecialRenderer {
|
||||
public static ModelDefender modelDefender = new ModelDefender();
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5);
|
||||
|
||||
renderCore((TileDefender) tileEntity, partialTick);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public static void renderCore(TileDefender tile, float partialTick) {
|
||||
GL11.glPushMatrix();
|
||||
float scale = (1F / 16F);
|
||||
GL11.glRotated(180, 2, 0, 0);
|
||||
|
||||
/*
|
||||
switch (tile.facingDirection) {
|
||||
case 1:
|
||||
GL11.glRotated(180, -1, 0, 0);
|
||||
break;
|
||||
case 2:
|
||||
GL11.glRotated(90, 1, 0, 0);
|
||||
break;
|
||||
case 3:
|
||||
GL11.glRotated(90, -1, 0, 0);
|
||||
break;
|
||||
case 4:
|
||||
GL11.glRotated(90, 0, 0, -1);
|
||||
break;
|
||||
case 5:
|
||||
GL11.glRotated(90, 0, 0, 1);
|
||||
}
|
||||
*/
|
||||
|
||||
ResourceHandler.bindResource("textures/models/defender.png");
|
||||
modelDefender.render(null, tile.modelIllumination, 0F, 0F, 0F, 0F, scale);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ import fr.jackcartersmith.orbsat.client.gui.OSGuiHandler;
|
||||
import fr.jackcartersmith.orbsat.common.handler.FMLEventHandler;
|
||||
import fr.jackcartersmith.orbsat.common.lib.OSConstants;
|
||||
import fr.jackcartersmith.orbsat.common.lib.OSRefs;
|
||||
import fr.jackcartersmith.orbsat.common.tileentities.TileDefender;
|
||||
import fr.jackcartersmith.orbsat.common.utils.OSLogHelper;
|
||||
import net.minecraft.client.audio.ISound;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@ -81,7 +82,7 @@ public class CommonProxy {
|
||||
}
|
||||
|
||||
public void registerTileEntities() {
|
||||
//GameRegistry.registerTileEntity(DefenderTileEntity.class, OSRefs.RESOURCESPREFIX + "TileDefender");
|
||||
GameRegistry.registerTileEntity(TileDefender.class, OSRefs.RESOURCESPREFIX + "TileDefender");
|
||||
|
||||
|
||||
|
||||
|
@ -3,8 +3,11 @@ package fr.jackcartersmith.orbsat.common;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import fr.jackcartersmith.orbsat.OrbitalSatellite;
|
||||
import fr.jackcartersmith.orbsat.common.blocks.BlockOS;
|
||||
import fr.jackcartersmith.orbsat.common.blocks.Defender;
|
||||
import fr.jackcartersmith.orbsat.common.lib.OSRefs;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@GameRegistry.ObjectHolder(OSRefs.MODID)
|
||||
@ -22,6 +25,10 @@ public class OSBlocks {
|
||||
public static BlockOS laserDef;
|
||||
|
||||
public static void init(){
|
||||
defender = new Defender();
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
laserLow = new LaserLowBlock(Material.fire).setBlockName("obLaserLow").setBlockTextureName(OSRefs.MODID + ":laserLow").setHardness(-1.0F).setResistance(-1.0F).setLightLevel(25.0F);;
|
||||
@ -87,4 +94,22 @@ public class OSBlocks {
|
||||
resurrectionStone = new ItemStack(ModBlocks.draconiumBlock, 1, 1);
|
||||
*/
|
||||
}
|
||||
|
||||
public static void register(BlockOS block) {
|
||||
String name = block.getUnwrappedUnlocalizedName(block.getUnlocalizedName());
|
||||
//if (isEnabled(block)) GameRegistry.registerBlock(block, name.substring(name.indexOf(":") + 1));
|
||||
GameRegistry.registerBlock(block, name.substring(name.indexOf(":") + 1));
|
||||
}
|
||||
|
||||
public static void register(BlockOS block, Class<? extends ItemBlock> item) {
|
||||
String name = block.getUnwrappedUnlocalizedName(block.getUnlocalizedName());
|
||||
//if (isEnabled(block)) GameRegistry.registerBlock(block, item, name.substring(name.indexOf(":") + 1));
|
||||
GameRegistry.registerBlock(block, item, name.substring(name.indexOf(":") + 1));
|
||||
}
|
||||
|
||||
public static void registerOther(Block block) {
|
||||
String name = block.getUnlocalizedName().substring(block.getUnlocalizedName().indexOf(".") + 1);
|
||||
//if (isEnabled(block)) GameRegistry.registerBlock(block, name.substring(name.indexOf(":") + 1));
|
||||
GameRegistry.registerBlock(block, name.substring(name.indexOf(":") + 1));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package fr.jackcartersmith.orbsat.common;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import fr.jackcartersmith.orbsat.OrbitalSatellite;
|
||||
import fr.jackcartersmith.orbsat.common.items.AdvancedExtrapolCircuit;
|
||||
import fr.jackcartersmith.orbsat.common.items.AdvancedTargetDevice;
|
||||
import fr.jackcartersmith.orbsat.common.items.BasicExtrapolCircuit;
|
||||
@ -13,8 +12,6 @@ import fr.jackcartersmith.orbsat.common.items.PhotonCapacitor;
|
||||
import fr.jackcartersmith.orbsat.common.items.PhotonLense;
|
||||
import fr.jackcartersmith.orbsat.common.items.PhotonCondenser;
|
||||
import fr.jackcartersmith.orbsat.common.lib.OSRefs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@GameRegistry.ObjectHolder(OSRefs.MODID)
|
||||
public class OSItems{
|
||||
|
@ -0,0 +1,39 @@
|
||||
package fr.jackcartersmith.orbsat.common.blocks;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockContainerOS extends BlockOS implements ITileEntityProvider{
|
||||
public BlockContainerOS(final Material material) {
|
||||
super(material);
|
||||
this.isBlockContainer = true;
|
||||
}
|
||||
|
||||
public BlockContainerOS() {
|
||||
super(Material.rock);
|
||||
this.isBlockContainer = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void onBlockAdded(World world, int x, int y, int z) {
|
||||
super.onBlockAdded(world, x, y, z);
|
||||
}
|
||||
|
||||
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
|
||||
super.breakBlock(world, x, y, z, block, meta);
|
||||
world.removeTileEntity(x, y, z);
|
||||
}
|
||||
|
||||
public boolean onBlockEventReceived(World world, int x, int y, int z, int p_149696_5_, int p_149696_6_) {
|
||||
super.onBlockEventReceived(world, x, y, z, p_149696_5_, p_149696_6_);
|
||||
TileEntity tileentity = world.getTileEntity(x, y, z);
|
||||
return tileentity != null ? tileentity.receiveClientEvent(p_149696_5_, p_149696_6_) : false;
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package fr.jackcartersmith.orbsat.common.blocks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class BlockCustomDrop extends BlockContainerOS{
|
||||
public BlockCustomDrop(final Material material) {
|
||||
super(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* If true the tile will drop its inventory when broken
|
||||
*/
|
||||
protected abstract boolean dropInventory();
|
||||
|
||||
/**
|
||||
* If true the tile will drop a custom block with custom data when broken
|
||||
*/
|
||||
protected abstract boolean hasCustomDropps();
|
||||
|
||||
/**
|
||||
* Use to specify custom drops
|
||||
*/
|
||||
protected abstract void getCustomTileEntityDrops(TileEntity te, List<ItemStack> droppes);
|
||||
|
||||
/*
|
||||
private void getCustomDrops(TileEntity te, List<ItemStack> droppes) {
|
||||
if (te == null) return;
|
||||
if (hasCustomDropps()) {
|
||||
getCustomTileEntityDrops(te, droppes);
|
||||
}
|
||||
if (dropInventory() && te instanceof IInventory) {
|
||||
droppes.addAll(InventoryUtils.getInventoryContents((IInventory) te));
|
||||
for (int i = 0; i < ((IInventory) te).getSizeInventory(); i++)
|
||||
((IInventory) te).setInventorySlotContents(i, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
|
||||
if (willHarvest) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
|
||||
boolean result = super.removedByPlayer(world, player, x, y, z, willHarvest);
|
||||
|
||||
if (result) {
|
||||
List<ItemStack> teDrops = Lists.newArrayList();
|
||||
getCustomDrops(te, teDrops);
|
||||
for (ItemStack drop : teDrops)
|
||||
dropBlockAsItem(world, x, y, z, drop);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return super.removedByPlayer(world, player, x, y, z, willHarvest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
|
||||
ArrayList<ItemStack> result = Lists.newArrayList();
|
||||
if (!hasCustomDropps()) result.addAll(super.getDrops(world, x, y, z, metadata, fortune));
|
||||
if (hasCustomDropps() || dropInventory()) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
getCustomDrops(te, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package fr.jackcartersmith.orbsat.common.blocks;
|
||||
|
||||
import java.util.List;
|
||||
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import fr.jackcartersmith.orbsat.OrbitalSatellite;
|
||||
import fr.jackcartersmith.orbsat.common.OSBlocks;
|
||||
import fr.jackcartersmith.orbsat.common.lib.OSRefs;
|
||||
import fr.jackcartersmith.orbsat.common.lib.OSStrings;
|
||||
import fr.jackcartersmith.orbsat.common.tileentities.TileDefender;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class Defender extends BlockCustomDrop {
|
||||
public Defender() {
|
||||
super(Material.iron);
|
||||
this.setBlockName(OSStrings.defenderName);
|
||||
this.setCreativeTab(OrbitalSatellite.OSCreaTab);
|
||||
this.setStepSound(soundTypeStone);
|
||||
this.setBlockBounds(0f, 0f, 0f, 1f, 0.5f, 1f);
|
||||
OSBlocks.register(this);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister iconRegister) {
|
||||
blockIcon = iconRegister.registerIcon(OSRefs.RESOURCESPREFIX + "machine_side");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
return new TileDefender();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float prx, float pry, float prz) {
|
||||
if (!world.isRemote) {
|
||||
//FMLNetworkHandler.openGui(player, OrbitalSatellite.instance, GuiHandler.GUIID_ENERGY_INFUSER, world, x, y, z);
|
||||
}
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
return true;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean dropInventory() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasCustomDropps() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getCustomTileEntityDrops(TileEntity te, List<ItemStack> droppes) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSideBeRendered(IBlockAccess access, int x, int y, int z, int side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side) {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package fr.jackcartersmith.orbsat.common.container;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import fr.jackcartersmith.orbsat.OrbitalSatellite;
|
||||
import fr.jackcartersmith.orbsat.common.lib.OSRefs;
|
||||
import fr.jackcartersmith.orbsat.common.network.TileObjectPacket;
|
||||
import fr.jackcartersmith.orbsat.common.tileentities.TileObjectSync;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
||||
public abstract class ContainerDataSync extends Container {
|
||||
|
||||
//TODO WTF? Was i sleep coding when i wrote this? In 1.8 re write this as a common container class for all mod containers and use a dedicated sender/receiver method for each data type i want to send (Unless i think of something better between now and then)
|
||||
|
||||
/**
|
||||
* Sends two ints to the client-side Container. Normally the first int identifies which variable to update, and the second contains the new
|
||||
* value.
|
||||
* if tile != null the packet will be sent to the tile client tile instead of the client container.
|
||||
*/
|
||||
public Object sendObjectToClient(TileObjectSync tile, int index, Object object) {
|
||||
for (Object p : crafters) {
|
||||
OrbitalSatellite.network.sendTo(new TileObjectPacket(tile, OSRefs.INT_ID, index, object), (EntityPlayerMP) p);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends two ints to the server-side Container. Normally the first int identifies which variable to update, and the second contains the new
|
||||
* value.
|
||||
* if tile != null the packet will be sent to the tile client tile instead of the client container.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Object sendObjectToServer(TileObjectSync tile, int index, Object object) {
|
||||
OrbitalSatellite.network.sendToServer(new TileObjectPacket(tile, OSRefs.INT_ID, index, object));
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a packet is received from ether the client or the server
|
||||
*/
|
||||
public abstract void receiveSyncData(int index, int value);
|
||||
}
|
@ -10,4 +10,6 @@ public class OSStrings {
|
||||
public static final String basicTargetDeviceName = "basicTargetDevice";
|
||||
public static final String advancedTargetDeviceName = "advancedTargetDevice";
|
||||
public static final String involvedTargetDeviceName = "involvedTargetDevice";
|
||||
|
||||
public static final String defenderName = "defender";
|
||||
}
|
||||
|
@ -0,0 +1,101 @@
|
||||
package fr.jackcartersmith.orbsat.common.network;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import fr.jackcartersmith.orbsat.common.container.ContainerDataSync;
|
||||
import fr.jackcartersmith.orbsat.common.tileentities.TileObjectSync;
|
||||
import fr.jackcartersmith.orbsat.common.utils.DataUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class TileObjectPacket implements IMessage {
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
short index;
|
||||
short dataType = -1;
|
||||
Object object;
|
||||
boolean isContainerPacket;
|
||||
|
||||
/**
|
||||
* Used for Tile and Container synchronization
|
||||
*/
|
||||
public TileObjectPacket() {
|
||||
}
|
||||
|
||||
public TileObjectPacket(TileObjectSync tile, byte dataType, int index, Object object) {
|
||||
this.isContainerPacket = tile == null;
|
||||
if (!isContainerPacket) {
|
||||
this.x = tile.xCoord;
|
||||
this.y = tile.yCoord;
|
||||
this.z = tile.zCoord;
|
||||
}
|
||||
this.dataType = dataType;
|
||||
this.object = object;
|
||||
this.index = (short) index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf bytes) {
|
||||
bytes.writeBoolean(isContainerPacket);
|
||||
|
||||
if (!isContainerPacket) {
|
||||
bytes.writeInt(x);
|
||||
bytes.writeInt(y);
|
||||
bytes.writeInt(z);
|
||||
}
|
||||
|
||||
bytes.writeByte(dataType);
|
||||
bytes.writeShort(index);
|
||||
|
||||
DataUtils.instance.writeObjectToBytes(bytes, dataType, object);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf bytes) {
|
||||
isContainerPacket = bytes.readBoolean();
|
||||
|
||||
if (!isContainerPacket) {
|
||||
x = bytes.readInt();
|
||||
y = bytes.readInt();
|
||||
z = bytes.readInt();
|
||||
}
|
||||
|
||||
dataType = bytes.readByte();
|
||||
index = bytes.readShort();
|
||||
|
||||
object = DataUtils.instance.readObjectFromBytes(bytes, dataType);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<TileObjectPacket, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(TileObjectPacket message, MessageContext ctx) {
|
||||
if (ctx.side == Side.CLIENT) {
|
||||
if (message.isContainerPacket) {
|
||||
ContainerDataSync container = Minecraft.getMinecraft().thePlayer.openContainer instanceof ContainerDataSync ? (ContainerDataSync) Minecraft.getMinecraft().thePlayer.openContainer : null;
|
||||
if (container == null) return null;
|
||||
container.receiveSyncData(message.index, (Integer) message.object);
|
||||
} else {
|
||||
if (!(Minecraft.getMinecraft().theWorld.getTileEntity(message.x, message.y, message.z) instanceof TileObjectSync))
|
||||
return null;
|
||||
((TileObjectSync) Minecraft.getMinecraft().theWorld.getTileEntity(message.x, message.y, message.z)).receiveObjectFromServer(message.index, message.object);
|
||||
}
|
||||
} else {
|
||||
if (message.isContainerPacket) {
|
||||
ContainerDataSync container = ctx.getServerHandler().playerEntity.openContainer instanceof ContainerDataSync ? (ContainerDataSync) ctx.getServerHandler().playerEntity.openContainer : null;
|
||||
if (container == null) return null;
|
||||
container.receiveSyncData(message.index, (Integer) message.object);
|
||||
} else {
|
||||
if (!(ctx.getServerHandler().playerEntity.worldObj.getTileEntity(message.x, message.y, message.z) instanceof TileObjectSync))
|
||||
return null;
|
||||
((TileObjectSync) ctx.getServerHandler().playerEntity.worldObj.getTileEntity(message.x, message.y, message.z)).receiveObjectFromClient(message.index, message.object);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package fr.jackcartersmith.orbsat.common.tileentities;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
//public class TileDefender extends TileObjectSync implements IEnergyReceiver, ISidedInventory {
|
||||
public class TileDefender extends TileObjectSync {
|
||||
public float modelIllumination = 1F;
|
||||
public int facingDirection = ForgeDirection.UP.ordinal();
|
||||
public boolean isValid = false;
|
||||
public int tick = 0;
|
||||
|
||||
//@SideOnly(Side.CLIENT)
|
||||
//private ParticleReactorBeam beam;
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
//masterLocation.writeToNBT(compound, "Master");
|
||||
compound.setInteger("Facing", facingDirection);
|
||||
//compound.setBoolean("IsValid", isValid);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
|
||||
NBTTagCompound compound = pkt.func_148857_g();
|
||||
//masterLocation.readFromNBT(compound, "Master");
|
||||
facingDirection = compound.getInteger("Facing");
|
||||
//isValid = compound.getBoolean("IsValid");
|
||||
super.onDataPacket(net, pkt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
super.writeToNBT(compound);
|
||||
/*
|
||||
masterLocation.writeToNBT(compound, "Master");
|
||||
compound.setInteger("Facing", facingDirection);
|
||||
compound.setBoolean("IsValid", isValid);
|
||||
compound.setInteger("RedstoneMode", redstoneMode);
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
super.readFromNBT(compound);
|
||||
/*
|
||||
masterLocation.readFromNBT(compound, "Master");
|
||||
facingDirection = compound.getInteger("Facing");
|
||||
isValid = compound.getBoolean("IsValid");
|
||||
redstoneMode = compound.getInteger("RedstoneMode");
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package fr.jackcartersmith.orbsat.common.tileentities;
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
import fr.jackcartersmith.orbsat.OrbitalSatellite;
|
||||
import fr.jackcartersmith.orbsat.common.network.TileObjectPacket;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class TileObjectSync extends TileEntity{
|
||||
/**
|
||||
* Sends a primitive to the client in the form of an object
|
||||
*/
|
||||
public Object sendObjectToClient(byte dataType, int index, Object object) {
|
||||
return sendObjectToClient(dataType, index, object, new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 64));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a primitive to the client in the form of an object
|
||||
*/
|
||||
public Object sendObjectToClient(byte dataType, int index, Object object, TargetPoint point) {
|
||||
OrbitalSatellite.network.sendToAllAround(new TileObjectPacket(this, dataType, index, object), point);
|
||||
return object;
|
||||
}
|
||||
|
||||
public Object sendObjectToServer(byte dataType, int index, Object object) {
|
||||
OrbitalSatellite.network.sendToServer(new TileObjectPacket(this, dataType, index, object));
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives an object from the server
|
||||
*/
|
||||
public void receiveObjectFromClient(int index, Object object) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives an object from the server
|
||||
*/
|
||||
public void receiveObjectFromServer(int index, Object object) {
|
||||
}
|
||||
}
|
@ -0,0 +1,255 @@
|
||||
package fr.jackcartersmith.orbsat.common.utils;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import fr.jackcartersmith.orbsat.common.lib.OSRefs;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class DataUtils {
|
||||
public static DataUtils instance = new DataUtils();
|
||||
|
||||
public void writeObjectToBytes(ByteBuf bytes, int dataType, Object object){
|
||||
switch (dataType){
|
||||
case OSRefs.BYTE_ID:
|
||||
bytes.writeByte((Byte)object);
|
||||
break;
|
||||
case OSRefs.SHORT_ID:
|
||||
bytes.writeShort((Short) object);
|
||||
break;
|
||||
case OSRefs.INT_ID:
|
||||
bytes.writeInt((Integer) object);
|
||||
break;
|
||||
case OSRefs.LONG_ID:
|
||||
bytes.writeLong((Long) object);
|
||||
break;
|
||||
case OSRefs.FLOAT_ID:
|
||||
bytes.writeFloat((Float) object);
|
||||
break;
|
||||
case OSRefs.DOUBLE_ID:
|
||||
bytes.writeDouble((Double) object);
|
||||
break;
|
||||
case OSRefs.CHAR_ID:
|
||||
bytes.writeChar((Character) object);
|
||||
break;
|
||||
case OSRefs.STRING_ID:
|
||||
ByteBufUtils.writeUTF8String(bytes, (String) object);
|
||||
break;
|
||||
case OSRefs.BOOLEAN_ID:
|
||||
bytes.writeBoolean((Boolean) object);
|
||||
break;
|
||||
case OSRefs.INT_PAIR_ID:
|
||||
bytes.writeInt(((IntPair)object).i1);
|
||||
bytes.writeInt(((IntPair)object).i2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Object readObjectFromBytes(ByteBuf bytes, int dataType){
|
||||
switch (dataType){
|
||||
case OSRefs.BYTE_ID:
|
||||
return bytes.readByte();
|
||||
case OSRefs.SHORT_ID:
|
||||
return bytes.readShort();
|
||||
case OSRefs.INT_ID:
|
||||
return bytes.readInt();
|
||||
case OSRefs.LONG_ID:
|
||||
return bytes.readLong();
|
||||
case OSRefs.FLOAT_ID:
|
||||
return bytes.readFloat();
|
||||
case OSRefs.DOUBLE_ID:
|
||||
return bytes.readDouble();
|
||||
case OSRefs.CHAR_ID:
|
||||
return bytes.readChar();
|
||||
case OSRefs.STRING_ID:
|
||||
return ByteBufUtils.readUTF8String(bytes);
|
||||
case OSRefs.BOOLEAN_ID:
|
||||
return bytes.readBoolean();
|
||||
case OSRefs.INT_PAIR_ID:
|
||||
IntPair tx = new IntPair(0, 0);
|
||||
tx.i1 = bytes.readInt();
|
||||
tx.i2 = bytes.readInt();
|
||||
return tx;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void writeObjectToItem(ItemStack stack, Object value, int datatype, String name){
|
||||
switch (datatype){
|
||||
case OSRefs.BYTE_ID:
|
||||
ItemNBTHelper.setByte(stack, name, (Byte) value);
|
||||
break;
|
||||
case OSRefs.SHORT_ID:
|
||||
ItemNBTHelper.setShort(stack, name, (Short) value);
|
||||
break;
|
||||
case OSRefs.INT_ID:
|
||||
ItemNBTHelper.setInteger(stack, name, (Integer) value);
|
||||
break;
|
||||
case OSRefs.LONG_ID:
|
||||
ItemNBTHelper.setLong(stack, name, (Long) value);
|
||||
break;
|
||||
case OSRefs.FLOAT_ID:
|
||||
ItemNBTHelper.setFloat(stack, name, (Float) value);
|
||||
break;
|
||||
case OSRefs.DOUBLE_ID:
|
||||
ItemNBTHelper.setDouble(stack, name, (Double) value);
|
||||
break;
|
||||
// case OSRefs.CHAR_ID:
|
||||
// ItemNBTHelper.setChar(stack, value.name, (Byte)value.value);
|
||||
// break;
|
||||
case OSRefs.STRING_ID:
|
||||
ItemNBTHelper.setString(stack, name, (String) value);
|
||||
break;
|
||||
case OSRefs.BOOLEAN_ID:
|
||||
ItemNBTHelper.setBoolean(stack, name, (Boolean) value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeObjectToCompound(NBTTagCompound compound, Object value, int datatype, String name){
|
||||
switch (datatype){
|
||||
case OSRefs.BYTE_ID:
|
||||
compound.setByte(name, (Byte) value);
|
||||
break;
|
||||
case OSRefs.SHORT_ID:
|
||||
compound.setShort(name, (Short) value);
|
||||
break;
|
||||
case OSRefs.INT_ID:
|
||||
compound.setInteger(name, (Integer) value);
|
||||
break;
|
||||
case OSRefs.LONG_ID:
|
||||
compound.setLong(name, (Long) value);
|
||||
break;
|
||||
case OSRefs.FLOAT_ID:
|
||||
compound.setFloat(name, (Float) value);
|
||||
break;
|
||||
case OSRefs.DOUBLE_ID:
|
||||
compound.setDouble(name, (Double) value);
|
||||
break;
|
||||
// case OSRefs.CHAR_ID:
|
||||
// ItemNBTHelper.setChar(stack, value.name, (Byte)value.value);
|
||||
// break;
|
||||
case OSRefs.STRING_ID:
|
||||
compound.setString(name, (String) value);
|
||||
break;
|
||||
case OSRefs.BOOLEAN_ID:
|
||||
compound.setBoolean(name, (Boolean) value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object readObjectFromItem(ItemStack stack, int dataType, String name, Object defaultExpected){
|
||||
switch (dataType){
|
||||
case OSRefs.BYTE_ID:
|
||||
return ItemNBTHelper.getByte(stack, name, (Byte)defaultExpected);
|
||||
case OSRefs.SHORT_ID:
|
||||
return ItemNBTHelper.getShort(stack, name, (Short)defaultExpected);
|
||||
case OSRefs.INT_ID:
|
||||
return ItemNBTHelper.getInteger(stack, name, (Integer)defaultExpected);
|
||||
case OSRefs.LONG_ID:
|
||||
return ItemNBTHelper.getLong(stack, name, (Long)defaultExpected);
|
||||
case OSRefs.FLOAT_ID:
|
||||
return ItemNBTHelper.getFloat(stack, name, (Float)defaultExpected);
|
||||
case OSRefs.DOUBLE_ID:
|
||||
return ItemNBTHelper.getDouble(stack, name, (Double)defaultExpected);
|
||||
//case OSRefs.CHAR_ID:
|
||||
case OSRefs.STRING_ID:
|
||||
return ItemNBTHelper.getString(stack, name, (String)defaultExpected);
|
||||
case OSRefs.BOOLEAN_ID:
|
||||
return ItemNBTHelper.getBoolean(stack, name, (Boolean)defaultExpected);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object readObjectFromItem(ItemStack stack, int dataType, String name){
|
||||
switch (dataType){
|
||||
case OSRefs.BYTE_ID:
|
||||
return ItemNBTHelper.getByte(stack, name, (byte)0);
|
||||
case OSRefs.SHORT_ID:
|
||||
return ItemNBTHelper.getShort(stack, name, (short) 0);
|
||||
case OSRefs.INT_ID:
|
||||
return ItemNBTHelper.getInteger(stack, name, 0);
|
||||
case OSRefs.LONG_ID:
|
||||
return ItemNBTHelper.getLong(stack, name, 0L);
|
||||
case OSRefs.FLOAT_ID:
|
||||
return ItemNBTHelper.getFloat(stack, name, 0F);
|
||||
case OSRefs.DOUBLE_ID:
|
||||
return ItemNBTHelper.getDouble(stack, name, 0D);
|
||||
//case OSRefs.CHAR_ID:
|
||||
case OSRefs.STRING_ID:
|
||||
return ItemNBTHelper.getString(stack, name, "");
|
||||
case OSRefs.BOOLEAN_ID:
|
||||
return ItemNBTHelper.getBoolean(stack, name, false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object readObjectFromCompound(NBTTagCompound compound, int dataType, String name, Object defaultExpected){
|
||||
switch (dataType){
|
||||
case OSRefs.BYTE_ID:
|
||||
return compound.hasKey(name) ? compound.getByte(name) : (Byte)defaultExpected;
|
||||
case OSRefs.SHORT_ID:
|
||||
return compound.hasKey(name) ? compound.getShort(name) : (Short)defaultExpected;
|
||||
case OSRefs.INT_ID:
|
||||
return compound.hasKey(name) ? compound.getInteger(name) : (Integer)defaultExpected;
|
||||
case OSRefs.LONG_ID:
|
||||
return compound.hasKey(name) ? compound.getLong(name) : (Long)defaultExpected;
|
||||
case OSRefs.FLOAT_ID:
|
||||
return compound.hasKey(name) ? compound.getFloat(name) : (Float)defaultExpected;
|
||||
case OSRefs.DOUBLE_ID:
|
||||
return compound.hasKey(name) ? compound.getDouble(name) : (Double)defaultExpected;
|
||||
//case OSRefs.CHAR_ID:
|
||||
case OSRefs.STRING_ID:
|
||||
return compound.hasKey(name) ? compound.getString(name) : (String)defaultExpected;
|
||||
case OSRefs.BOOLEAN_ID:
|
||||
return compound.hasKey(name) ? compound.getBoolean(name) : (Boolean)defaultExpected;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class IntPair
|
||||
{
|
||||
public int i1;
|
||||
public int i2;
|
||||
|
||||
public IntPair(int i1, int i2)
|
||||
{
|
||||
this.i1 = i1;
|
||||
this.i2 = i2;
|
||||
}
|
||||
}
|
||||
|
||||
public static class XZPair<X, Z>{
|
||||
public X x;
|
||||
public Z z;
|
||||
|
||||
public XZPair(X x, Z z){
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public X getKey() { return x; }
|
||||
|
||||
public Z getValue() { return z; }
|
||||
}
|
||||
|
||||
public static class XYZTri<X, Y, Z>{
|
||||
public X x;
|
||||
public Y y;
|
||||
public Z z;
|
||||
|
||||
public XYZTri(X x, Y y, Z z){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatFileSize(long size) {
|
||||
if(size <= 0) return "0";
|
||||
final String[] units = new String[] { "B", "kB", "MB", "GB", "TB" };
|
||||
int digitGroups = (int) (Math.log10(size)/Math.log10(1024));
|
||||
return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
package fr.jackcartersmith.orbsat.common.utils;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class ItemNBTHelper {
|
||||
// SETTERS ///////////////////////////////////////////////////////////////////
|
||||
public static NBTTagCompound getCompound(ItemStack stack){
|
||||
if (stack.getTagCompound() == null) stack.setTagCompound(new NBTTagCompound());
|
||||
return stack.getTagCompound();
|
||||
}
|
||||
|
||||
public static ItemStack setByte(ItemStack stack, String tag, byte b)
|
||||
{
|
||||
NBTTagCompound compound = getCompound(stack);
|
||||
compound.setByte(tag, b);
|
||||
stack.setTagCompound(compound);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack setBoolean(ItemStack stack, String tag, boolean b)
|
||||
{
|
||||
NBTTagCompound compound = getCompound(stack);
|
||||
compound.setBoolean(tag, b);
|
||||
stack.setTagCompound(compound);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack setShort(ItemStack stack, String tag, short s)
|
||||
{
|
||||
NBTTagCompound compound = getCompound(stack);
|
||||
compound.setShort(tag, s);
|
||||
stack.setTagCompound(compound);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack setInteger(ItemStack stack, String tag, int i)
|
||||
{
|
||||
NBTTagCompound compound = getCompound(stack);
|
||||
compound.setInteger(tag, i);
|
||||
stack.setTagCompound(compound);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack setLong(ItemStack stack, String tag, long i)
|
||||
{
|
||||
NBTTagCompound compound = getCompound(stack);
|
||||
compound.setLong(tag, i);
|
||||
stack.setTagCompound(compound);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack setFloat(ItemStack stack, String tag, float f)
|
||||
{
|
||||
NBTTagCompound compound = getCompound(stack);
|
||||
compound.setFloat(tag, f);
|
||||
stack.setTagCompound(compound);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack setDouble(ItemStack stack, String tag, double d)
|
||||
{
|
||||
NBTTagCompound compound = getCompound(stack);
|
||||
compound.setDouble(tag, d);
|
||||
stack.setTagCompound(compound);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack setString(ItemStack stack, String tag, String s) {
|
||||
NBTTagCompound compound = getCompound(stack);
|
||||
compound.setString(tag, s);
|
||||
stack.setTagCompound(compound);
|
||||
return stack;
|
||||
}
|
||||
|
||||
// GETTERS ///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static boolean verifyExistance(ItemStack stack, String tag) {
|
||||
NBTTagCompound compound = stack.getTagCompound();
|
||||
if (compound == null)
|
||||
return false;
|
||||
else
|
||||
return stack.getTagCompound().hasKey(tag);
|
||||
}
|
||||
|
||||
public static byte getByte(ItemStack stack, String tag, byte defaultExpected) {
|
||||
return verifyExistance(stack, tag) ? stack.getTagCompound().getByte(tag) : defaultExpected;
|
||||
}
|
||||
|
||||
public static boolean getBoolean(ItemStack stack, String tag, boolean defaultExpected) {
|
||||
return verifyExistance(stack, tag) ? stack.getTagCompound().getBoolean(tag) : defaultExpected;
|
||||
}
|
||||
|
||||
public static short getShort(ItemStack stack, String tag, short defaultExpected) {
|
||||
return verifyExistance(stack, tag) ? stack.getTagCompound().getShort(tag) : defaultExpected;
|
||||
}
|
||||
|
||||
public static int getInteger(ItemStack stack, String tag, int defaultExpected) {
|
||||
return verifyExistance(stack, tag) ? stack.getTagCompound().getInteger(tag) : defaultExpected;
|
||||
}
|
||||
|
||||
public static long getLong(ItemStack stack, String tag, long defaultExpected) {
|
||||
return verifyExistance(stack, tag) ? stack.getTagCompound().getLong(tag) : defaultExpected;
|
||||
}
|
||||
|
||||
public static float getFloat(ItemStack stack, String tag, float defaultExpected) {
|
||||
return verifyExistance(stack, tag) ? stack.getTagCompound().getFloat(tag) : defaultExpected;
|
||||
}
|
||||
|
||||
public static double getDouble(ItemStack stack, String tag, double defaultExpected) {
|
||||
return verifyExistance(stack, tag) ? stack.getTagCompound().getDouble(tag) : defaultExpected;
|
||||
}
|
||||
|
||||
public static String getString(ItemStack stack, String tag, String defaultExpected) {
|
||||
return verifyExistance(stack, tag) ? stack.getTagCompound().getString(tag) : defaultExpected;
|
||||
}
|
||||
}
|
@ -13,10 +13,10 @@ item.orbsat:advancedTargetDevice.name=Advanced Targeting Device
|
||||
item.orbsat:involvedTargetDevice.name=Involved Targeting Device
|
||||
|
||||
// Tiles --------------------------------------------------
|
||||
tile.orbsat:defender.name=Laser Defender
|
||||
tile.obOverrider.name=Laser Satelite Overrider
|
||||
tile.obExtender.name=Extender
|
||||
tile.obSatelite.name=Laser Satelite Prototype LX-I
|
||||
tile.obDefender.name=Laser Strike Defender
|
||||
tile.obAccelerator.name=Photon Accelerator
|
||||
tile.obDecelerator.name=Photon Deccelerator
|
||||
tile.obInverterAdv.name=Advanced Photonic Converter
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
Loading…
x
Reference in New Issue
Block a user