diff options
Diffstat (limited to 'src/Java/miscutil/xmod/ic2/block/RTGGenerator')
4 files changed, 428 insertions, 0 deletions
diff --git a/src/Java/miscutil/xmod/ic2/block/RTGGenerator/BlockRTG.java b/src/Java/miscutil/xmod/ic2/block/RTGGenerator/BlockRTG.java new file mode 100644 index 0000000000..bda119af5c --- /dev/null +++ b/src/Java/miscutil/xmod/ic2/block/RTGGenerator/BlockRTG.java @@ -0,0 +1,187 @@ +package miscutil.xmod.ic2.block.RTGGenerator; + +import ic2.core.IC2; +import ic2.core.Ic2Items; +import ic2.core.block.BlockMultiID; +import ic2.core.block.TileEntityBlock; +import ic2.core.block.generator.tileentity.TileEntityKineticGenerator; +import ic2.core.block.generator.tileentity.TileEntityRTGenerator; +import ic2.core.block.reactor.tileentity.TileEntityNuclearReactorElectric; +import ic2.core.init.InternalName; +import ic2.core.item.block.ItemGenerator; + +import java.util.Random; + +import miscutil.xmod.ic2.block.kieticgenerator.tileentity.TileEntityKineticWindGenerator; +import miscutil.xmod.ic2.item.IC2_Items; +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import org.apache.commons.lang3.mutable.MutableObject; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class BlockRTG + extends BlockMultiID +{ + public BlockRTG(InternalName internalName1) + { + super(internalName1, Material.iron, ItemGenerator.class); + + setHardness(3.0F); + setStepSound(soundTypeMetal); + + IC2_Items.blockRTG = new ItemStack(this, 1, 0); + IC2_Items.blockKineticGenerator = new ItemStack(this, 1, 1); + + GameRegistry.registerTileEntity(TileEntityRTG.class, "Radioisotope Thermoelectric Generator Mach II"); + GameRegistry.registerTileEntity(TileEntityKineticWindGenerator.class, "Kinetic Wind Generator Mach II"); + } + + @Override +public String getTextureFolder(int id) + { + return "generator"; + } + + @Override +public int damageDropped(int meta) + { + switch (meta) + { + case 2: + return 2; + } + return 0; + } + + @Override +public Class<? extends TileEntity> getTeClass(int meta, MutableObject<Class<?>[]> ctorArgTypes, MutableObject<Object[]> ctorArgs) + { + try + { + switch (meta) + { + case 0: + return TileEntityRTGenerator.class; + case 1: + return TileEntityKineticGenerator.class; + } + } + catch (Exception e) + { + throw new RuntimeException(e); + } + return null; + } + + /* + * + * { + case 0: + return TileEntityGenerator.class; + case 1: + return TileEntityGeoGenerator.class; + case 2: + return TileEntityWaterGenerator.class; + case 3: + return TileEntitySolarGenerator.class; + case 4: + return TileEntityWindGenerator.class; + case 5: + return TileEntityNuclearReactorElectric.class; + case 6: + return TileEntityRTGenerator.class; + case 7: + return TileEntitySemifluidGenerator.class; + case 8: + return TileEntityStirlingGenerator.class; + case 9: + return TileEntityKineticGenerator.class; + } + * + * (non-Javadoc) + * @see net.minecraft.block.Block#randomDisplayTick(net.minecraft.world.World, int, int, int, java.util.Random) + */ + + @Override +public void randomDisplayTick(World world, int x, int y, int z, Random random) + { + if (!IC2.platform.isRendering()) { + return; + } + int meta = world.getBlockMetadata(x, y, z); + if ((meta == 0) && (isActive(world, x, y, z))) + { + TileEntityBlock te = (TileEntityBlock)getOwnTe(world, x, y, z); + if (te == null) { + return; + } + int l = te.getFacing(); + float f = x + 0.5F; + float f1 = y + 0.0F + random.nextFloat() * 6.0F / 16.0F; + float f2 = z + 0.5F; + float f3 = 0.52F; + float f4 = random.nextFloat() * 0.6F - 0.3F; + switch (l) + { + case 4: + world.spawnParticle("smoke", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); + world.spawnParticle("flame", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); + break; + case 5: + world.spawnParticle("smoke", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); + world.spawnParticle("flame", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); + break; + case 2: + world.spawnParticle("smoke", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D); + world.spawnParticle("flame", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D); + break; + case 3: + world.spawnParticle("smoke", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D); + world.spawnParticle("flame", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D); + } + } + else if (meta == 5) + { + TileEntityNuclearReactorElectric te = (TileEntityNuclearReactorElectric)getOwnTe(world, x, y, z); + if (te == null) { + return; + } + int puffs = te.heat / 1000; + if (puffs <= 0) { + return; + } + puffs = world.rand.nextInt(puffs); + for (int n = 0; n < puffs; n++) { + world.spawnParticle("smoke", x + random.nextFloat(), y + 0.95F, z + random.nextFloat(), 0.0D, 0.0D, 0.0D); + } + puffs -= world.rand.nextInt(4) + 3; + for (int n = 0; n < puffs; n++) { + world.spawnParticle("flame", x + random.nextFloat(), y + 1.0F, z + random.nextFloat(), 0.0D, 0.0D, 0.0D); + } + } + } + + @Override +public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int side, float a, float b, float c) + { + if ((entityplayer.getCurrentEquippedItem() != null) && (entityplayer.getCurrentEquippedItem().isItemEqual(Ic2Items.reactorChamber))) { + return false; + } + return super.onBlockActivated(world, i, j, k, entityplayer, side, a, b, c); + } + + @Override +@SideOnly(Side.CLIENT) + public EnumRarity getRarity(ItemStack stack) + { + return stack.getItemDamage() == 5 ? EnumRarity.uncommon : EnumRarity.common; + } +} diff --git a/src/Java/miscutil/xmod/ic2/block/RTGGenerator/TileEntityRTG.java b/src/Java/miscutil/xmod/ic2/block/RTGGenerator/TileEntityRTG.java new file mode 100644 index 0000000000..f3b7949db2 --- /dev/null +++ b/src/Java/miscutil/xmod/ic2/block/RTGGenerator/TileEntityRTG.java @@ -0,0 +1,94 @@ +package miscutil.xmod.ic2.block.RTGGenerator; + +import ic2.core.ContainerBase; +import ic2.core.block.generator.tileentity.TileEntityBaseGenerator; +import ic2.core.block.invslot.InvSlot; +import miscutil.xmod.ic2.block.RTGGenerator.gui.CONTAINER_RadioThermalGenerator; +import miscutil.xmod.ic2.block.RTGGenerator.gui.GUI_RadioThermalGenerator; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.entity.player.EntityPlayer; + +public class TileEntityRTG +extends TileEntityBaseGenerator +{ + public final InvSlot fuelSlot; + + public TileEntityRTG() + { + super(Math.round(16.0F * efficiency), 1, 20000); + + this.fuelSlot = this.invSlots.get(0); + } + + @Override + public int gaugeFuelScaled(int i) + { + return i; + } + + @Override + public boolean gainEnergy() + { + int counter = 0; + for (int i = 0; i < this.fuelSlot.size(); i++) { + if (this.fuelSlot.get(i) != null) { + counter++; + } + } + if (counter == 0) { + return false; + } + this.storage += (int)(Math.pow(2.0D, counter - 1) * efficiency); + return true; + } + + @Override + public boolean gainFuel() + { + return false; + } + + @Override + public boolean needsFuel() + { + return true; + } + + @Override + public String getInventoryName() + { + return "RTGenerator"; + } + + + public Object getGui(EntityPlayer player, int data) + { + return new GUI_RadioThermalGenerator(this, player); + } + + + public Object getGuiContainer(EntityPlayer player, int data) + { + return new CONTAINER_RadioThermalGenerator(this, player); + } + + @Override + public boolean delayActiveUpdate() + { + return true; + } + + private static final float efficiency = 100; + + @Override + public GuiScreen getGui(EntityPlayer arg0, boolean arg1) { + getGui(arg0, 1); + return null; + } + + @Override + public ContainerBase<?> getGuiContainer(EntityPlayer arg0) { + getGuiContainer(arg0, 1); + return null; + } +} diff --git a/src/Java/miscutil/xmod/ic2/block/RTGGenerator/gui/CONTAINER_RadioThermalGenerator.java b/src/Java/miscutil/xmod/ic2/block/RTGGenerator/gui/CONTAINER_RadioThermalGenerator.java new file mode 100644 index 0000000000..b70bb6bd8d --- /dev/null +++ b/src/Java/miscutil/xmod/ic2/block/RTGGenerator/gui/CONTAINER_RadioThermalGenerator.java @@ -0,0 +1,98 @@ +package miscutil.xmod.ic2.block.RTGGenerator.gui; + +import miscutil.core.lib.CORE; +import miscutil.core.slots.SlotRTG; +import miscutil.xmod.ic2.block.RTGGenerator.TileEntityRTG; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import forestry.api.apiculture.IHiveFrame; +import forestry.core.gui.tooltips.ToolTip; + +public class CONTAINER_RadioThermalGenerator extends Container +{ + private TileEntityRTG te; + + public static final int INPUT_1 = 0; + private final ResourceLocation beeFrameIcon = new ResourceLocation(CORE.MODID, "textures/items/machine_Charger.png"); + public ToolTip newTip = new ToolTip(); + public final SlotRTG rtgSlot; + + private int slotID = 0; + + public CONTAINER_RadioThermalGenerator(TileEntityRTG te, EntityPlayer player) + { + this.te = te; + this.rtgSlot = new SlotRTG(te, slotID++, 80, 35); + + //Fuel Slot A + rtgSlot.setBackgroundIconTexture(beeFrameIcon); + + addSlotToContainer(rtgSlot); + + //Inventory + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 9; j++) + { + addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } + // Hotbar + for (int i = 0; i < 9; i++) + { + addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 142)); + } + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slotRaw) + { + ItemStack stack = null; + Slot slot = (Slot)inventorySlots.get(slotRaw); + + if (slot != null && slot.getHasStack()) + { + ItemStack stackInSlot = slot.getStack(); + stack = stackInSlot.copy(); + + + //If your inventory only stores certain instances of Items, + //you can implement shift-clicking to your inventory like this: + // Check that the item is the right type + if (!(stack.getItem() instanceof IHiveFrame)){ + return null; + } + + if (slotRaw < 1) + { + if (!mergeItemStack(stackInSlot, 3 * 9, inventorySlots.size(), true)) + { + return null; + } + } + else if (!mergeItemStack(stackInSlot, 0, 3 * 9, false)) + { + return null; + } + + if (stackInSlot.stackSize == 0) + { + slot.putStack((ItemStack)null); + } + else + { + slot.onSlotChanged(); + } + } + return stack; + } + + @Override + public boolean canInteractWith(EntityPlayer player) + { + return te.isUseableByPlayer(player); + } +}
\ No newline at end of file diff --git a/src/Java/miscutil/xmod/ic2/block/RTGGenerator/gui/GUI_RadioThermalGenerator.java b/src/Java/miscutil/xmod/ic2/block/RTGGenerator/gui/GUI_RadioThermalGenerator.java new file mode 100644 index 0000000000..4c9442d56d --- /dev/null +++ b/src/Java/miscutil/xmod/ic2/block/RTGGenerator/gui/GUI_RadioThermalGenerator.java @@ -0,0 +1,49 @@ +package miscutil.xmod.ic2.block.RTGGenerator.gui; + +import miscutil.core.lib.CORE; +import miscutil.xmod.ic2.block.RTGGenerator.TileEntityRTG; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +public class GUI_RadioThermalGenerator extends GuiContainer +{ + private ResourceLocation texture = new ResourceLocation(CORE.MODID, "textures/gui/machine_Charger.png"); + + private InventoryPlayer inventory; + private TileEntityRTG te; + + public GUI_RadioThermalGenerator(TileEntityRTG te, EntityPlayer player) + { + super(new CONTAINER_RadioThermalGenerator(te, player)); + inventory = player.inventory; + this.te = te; + } + + @Override + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) + { + Minecraft.getMinecraft().renderEngine.bindTexture(texture); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + + int x = (width - xSize) / 2; + int y = (height - ySize) / 2; + + drawTexturedModalRect(x, y, 0, 0, xSize, ySize); + } + + @Override + protected void drawGuiContainerForegroundLayer(int par1, int par2) + { + fontRendererObj.drawString(I18n.format("Alveary Frame Housing"), (xSize / 2) - (fontRendererObj.getStringWidth(I18n.format("Alveary Frame Housing")) / 2), 6, 4210752, false); + fontRendererObj.drawString(I18n.format(inventory.getInventoryName()), 8, ySize - 96 + 2, 4210752); + //fontRendererObj.drawString(I18n.format("Charge:"+te.getCharge()+"~"), 8, ySize - 96 + 2, 4210752); + //fontRendererObj.drawString(I18n.format("Progress:"+te.getProgress()+"ticks"), 80, ySize - 96 + 2, 4210752); + } +}
\ No newline at end of file |
