Fixing bugs, cleaning up code.

master
Droog71 2020-07-24 07:58:59 -04:00
parent f6d0002701
commit e9395b3c8c
43 changed files with 463 additions and 517 deletions

View File

@ -5,7 +5,7 @@ import java.util.Random;
import com.droog71.prospect.Prospect;
import com.droog71.prospect.blocks.ProspectBlockContainer;
import com.droog71.prospect.init.ProspectBlocks;
import com.droog71.prospect.tilentity.PrinterTileEntity;
import com.droog71.prospect.tilentity.FabricatorTileEntity;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
@ -20,9 +20,9 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class Printer extends ProspectBlockContainer
public class Fabricator extends ProspectBlockContainer
{
public Printer(String name, Material material)
public Fabricator(String name, Material material)
{
super(name, material);
}
@ -39,7 +39,7 @@ public class Printer extends ProspectBlockContainer
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Item.getItemFromBlock(ProspectBlocks.printer);
return Item.getItemFromBlock(ProspectBlocks.fabricator);
}
/**
@ -56,7 +56,7 @@ public class Printer extends ProspectBlockContainer
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof PrinterTileEntity)
if (tileentity instanceof FabricatorTileEntity)
{
playerIn.openGui(Prospect.instance, 1, worldIn, pos.getX(), pos.getY(), pos.getZ());
}
@ -71,7 +71,7 @@ public class Printer extends ProspectBlockContainer
@Override
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new PrinterTileEntity();
return new FabricatorTileEntity();
}
/**
@ -82,9 +82,9 @@ public class Printer extends ProspectBlockContainer
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof PrinterTileEntity)
if (tileentity instanceof FabricatorTileEntity)
{
InventoryHelper.dropInventoryItems(worldIn, pos, (PrinterTileEntity)tileentity);
InventoryHelper.dropInventoryItems(worldIn, pos, (FabricatorTileEntity)tileentity);
worldIn.updateComparatorOutputLevel(pos, this);
}
super.breakBlock(worldIn, pos, state);
@ -105,6 +105,6 @@ public class Printer extends ProspectBlockContainer
@Override
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(Item.getItemFromBlock(ProspectBlocks.printer));
return new ItemStack(Item.getItemFromBlock(ProspectBlocks.fabricator));
}
}

View File

@ -5,6 +5,7 @@ import com.droog71.prospect.tilentity.QuarryTileEntity;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class Quarry extends ProspectBlock
@ -25,4 +26,22 @@ public class Quarry extends ProspectBlock
{
return new QuarryTileEntity();
}
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof QuarryTileEntity)
{
for (BlockPos p : ((QuarryTileEntity) tileentity).quarryPositions)
{
worldIn.setBlockToAir(p);
}
}
super.breakBlock(worldIn, pos, state);
}
}

View File

@ -8,7 +8,7 @@ import java.util.Scanner;
public class ConfigHandler
{
public static boolean getSporesEnabled()
public static boolean toxicSporesEnabled()
{
File configFile = new File(System.getProperty("user.dir")+"/config/prospect.cfg");
if (configFile.exists())
@ -19,7 +19,7 @@ public class ConfigHandler
configFileScanner = new Scanner(configFile);
String configFileContents = configFileScanner.useDelimiter("\\Z").next();
configFileScanner.close();
String configValue = configFileContents.split(":")[1].toLowerCase();
String configValue = configFileContents.split(">")[1].split(":")[1].toLowerCase().trim();
if (configValue.equals("true"))
{
return true;
@ -27,7 +27,37 @@ public class ConfigHandler
}
catch (FileNotFoundException e)
{
System.out.println("Reactor turbines mod failed to find config file!");
System.out.println("Prospect mod failed to find config file!");
e.printStackTrace();
}
}
else
{
createConfigFile();
}
return false;
}
public static boolean purifierParticleEffectsEnabled()
{
File configFile = new File(System.getProperty("user.dir")+"/config/prospect.cfg");
if (configFile.exists())
{
Scanner configFileScanner;
try
{
configFileScanner = new Scanner(configFile);
String configFileContents = configFileScanner.useDelimiter("\\Z").next();
configFileScanner.close();
String configValue = configFileContents.split(">")[2].split(":")[1].toLowerCase().trim();
if (configValue.equals("true"))
{
return true;
}
}
catch (FileNotFoundException e)
{
System.out.println("Prospect mod failed to find config file!");
e.printStackTrace();
}
}
@ -50,7 +80,7 @@ public class ConfigHandler
try
{
f = new FileWriter(configFile,false);
f.write("toxic_spores_enabled:true");
f.write(">toxic_spores_enabled:true\n>purifier_particle_effects:true");
f.close();
}
catch (IOException ioe)

View File

@ -1,6 +1,21 @@
package com.droog71.prospect.fe;
import java.util.ArrayList;
import java.util.List;
import com.droog71.prospect.init.ProspectBlocks;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
public class ProspectEnergyStorage implements IEnergyStorage
@ -55,6 +70,73 @@ public class ProspectEnergyStorage implements IEnergyStorage
}
}
//Give energy to an adjacent block.
public List<IEnergyStorage> receivers(World world, BlockPos pos)
{
List<IEnergyStorage> receiversFound = new ArrayList<IEnergyStorage>();
BlockPos[] sides = {pos.add(0,1,0),pos.add(1,0,0),pos.add(0,0,1),pos.add(0,-1,0),pos.add(-1,0,0),pos.add(0,0,-1)};
for (BlockPos p : sides)
{
TileEntity otherTile = world.getTileEntity(p);
if (otherTile != null)
{
EnumFacing direction = null;
for (EnumFacing facing : EnumFacing.VALUES)
{
IEnergyStorage otherStorage = otherTile.getCapability(CapabilityEnergy.ENERGY,facing);
if (otherStorage != null)
{
if (direction == null)
{
direction = facing;
}
}
}
IEnergyStorage otherStorage = otherTile.getCapability(CapabilityEnergy.ENERGY,direction);
if (otherStorage != null)
{
receiversFound.add(otherStorage);
}
}
}
return receiversFound;
}
public void giveEnergy(ProspectEnergyStorage source, IEnergyStorage sink, int rating)
{
if (sink != null)
{
if (sink.canReceive()) //The adjacent block can receive the energy.
{
int demand = sink.getMaxEnergyStored() - sink.getEnergyStored(); //The energy required by the receiver.
int potential = Math.min(demand, rating); //Use the lower value.
int available = Math.min(potential, source.getEnergyStored()); //Use the lower value.
int difference = Math.max(0, ((source.getEnergyStored() - sink.getEnergyStored())/2)-1); //To keep power flow in the correct direction.
int output = Math.min(available, difference); //Use the lower value.
source.useEnergy(output); //Remove energy from the source.
sink.receiveEnergy(rating, true); //If this transaction overloads the receiver, it will explode.
if (sink != null) //Recipient did not explode.
{
sink.receiveEnergy(output,false); //Add the energy to the adjacent block.
}
}
}
}
//If an energy storage block's FE per tick rating is exceeded, it will explode.
public void explode(World world, BlockPos pos)
{
world.playSound(null, pos, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 0.5f, 1);
WorldServer w = (WorldServer) world;
w.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, pos.getX(), pos.getY(), pos.getZ(), 1, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.LAVA, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.FLAME, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
world.getBlockState(pos).getBlock().breakBlock(world, pos, ProspectBlocks.extruder.getDefaultState());
EntityItem item = new EntityItem(w, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ProspectBlocks.extruder));
w.spawnEntity(item);
world.setBlockToAir(pos);
}
@Override
public int extractEnergy(int maxExtract, boolean simulate)
{

View File

@ -1,7 +1,7 @@
package com.droog71.prospect.gui;
import com.droog71.prospect.inventory.PrinterContainer;
import com.droog71.prospect.tilentity.PrinterTileEntity;
import com.droog71.prospect.inventory.FabricatorContainer;
import com.droog71.prospect.tilentity.FabricatorTileEntity;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
@ -21,7 +21,7 @@ public class PrinterGUI extends GuiContainer
public PrinterGUI(InventoryPlayer playerInv, IInventory printerInv)
{
super(new PrinterContainer(playerInv, printerInv));
super(new FabricatorContainer(playerInv, printerInv));
this.playerInventory = playerInv;
this.tilePrinter = printerInv;
}
@ -60,7 +60,7 @@ public class PrinterGUI extends GuiContainer
int j = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
if (PrinterTileEntity.isEnergized(this.tilePrinter))
if (FabricatorTileEntity.isEnergized(this.tilePrinter))
{
int k = this.getBurnLeftScaled(13);
this.drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);

View File

@ -3,12 +3,12 @@ package com.droog71.prospect.gui;
import com.droog71.prospect.inventory.ExtruderContainer;
import com.droog71.prospect.inventory.LaunchPadContainer;
import com.droog71.prospect.inventory.PressContainer;
import com.droog71.prospect.inventory.PrinterContainer;
import com.droog71.prospect.inventory.FabricatorContainer;
import com.droog71.prospect.inventory.ReplicatorContainer;
import com.droog71.prospect.tilentity.ExtruderTileEntity;
import com.droog71.prospect.tilentity.LaunchPadTileEntity;
import com.droog71.prospect.tilentity.PressTileEntity;
import com.droog71.prospect.tilentity.PrinterTileEntity;
import com.droog71.prospect.tilentity.FabricatorTileEntity;
import com.droog71.prospect.tilentity.ReplicatorTileEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
@ -27,7 +27,7 @@ public class ProspectGuiHandler implements IGuiHandler
}
if (ID == 1)
{
return new PrinterContainer(player.inventory, (PrinterTileEntity)world.getTileEntity(new BlockPos(x,y,z)));
return new FabricatorContainer(player.inventory, (FabricatorTileEntity)world.getTileEntity(new BlockPos(x,y,z)));
}
if (ID == 2)
{
@ -57,7 +57,7 @@ public class ProspectGuiHandler implements IGuiHandler
}
if (ID == 1)
{
return new PrinterGUI(player.inventory, (PrinterTileEntity)world.getTileEntity(new BlockPos(x,y,z)));
return new PrinterGUI(player.inventory, (FabricatorTileEntity)world.getTileEntity(new BlockPos(x,y,z)));
}
if (ID == 2)
{

View File

@ -6,7 +6,7 @@ import com.droog71.prospect.blocks.energy.Cable;
import com.droog71.prospect.blocks.energy.Extruder;
import com.droog71.prospect.blocks.energy.LaunchPad;
import com.droog71.prospect.blocks.energy.Press;
import com.droog71.prospect.blocks.energy.Printer;
import com.droog71.prospect.blocks.energy.Fabricator;
import com.droog71.prospect.blocks.energy.Purifier;
import com.droog71.prospect.blocks.energy.Quarry;
import com.droog71.prospect.blocks.energy.Replicator;
@ -17,7 +17,7 @@ import com.droog71.prospect.tilentity.CableTileEntity;
import com.droog71.prospect.tilentity.ExtruderTileEntity;
import com.droog71.prospect.tilentity.LaunchPadTileEntity;
import com.droog71.prospect.tilentity.PressTileEntity;
import com.droog71.prospect.tilentity.PrinterTileEntity;
import com.droog71.prospect.tilentity.FabricatorTileEntity;
import com.droog71.prospect.tilentity.PurifierTileEntity;
import com.droog71.prospect.tilentity.QuarryTileEntity;
import com.droog71.prospect.tilentity.ReplicatorTileEntity;
@ -46,7 +46,7 @@ public class ProspectBlocks
public static Block silicon_ore;
public static Block purifier;
public static Block quarry;
public static Block printer;
public static Block fabricator;
public static Block replicator;
public static Block quarry_frame;
public static Block quarry_tube;
@ -72,7 +72,7 @@ public class ProspectBlocks
static ExtruderTileEntity extruderTileEntity;
static PressTileEntity pressTileEntity;
static PurifierTileEntity purifierTileEntity;
static PrinterTileEntity printerTileEntity;
static FabricatorTileEntity fabricatorTileEntity;
static QuarryTileEntity quarryTileEntity;
static ReplicatorTileEntity replicatorTileEntity;
static SolarPanelTileEntity solarPanelTileEntity;
@ -86,7 +86,7 @@ public class ProspectBlocks
press = new Press("press",Material.IRON).setHardness(1.0f).setCreativeTab(Prospect.tabProspect);
purifier = new Purifier("purifier",Material.IRON).setHardness(1.0f).setCreativeTab(Prospect.tabProspect);
quarry = new Quarry("quarry",Material.IRON).setHardness(1.0f).setCreativeTab(Prospect.tabProspect);
printer = new Printer("printer",Material.IRON).setHardness(1.0f).setCreativeTab(Prospect.tabProspect);
fabricator = new Fabricator("fabricator",Material.IRON).setHardness(1.0f).setCreativeTab(Prospect.tabProspect);
replicator = new Replicator("replicator",Material.IRON).setHardness(1.0f).setCreativeTab(Prospect.tabProspect);
quarry_frame = new ProspectBlock("quarry_frame",Material.IRON).setHardness(1.0f).setCreativeTab(Prospect.tabProspect);
quarry_tube = new ProspectBlock("quarry_tube",Material.IRON).setHardness(1.0f).setCreativeTab(Prospect.tabProspect);
@ -117,7 +117,7 @@ public class ProspectBlocks
extruderTileEntity = new ExtruderTileEntity();
pressTileEntity = new PressTileEntity();
purifierTileEntity = new PurifierTileEntity();
printerTileEntity = new PrinterTileEntity();
fabricatorTileEntity = new FabricatorTileEntity();
quarryTileEntity = new QuarryTileEntity();
replicatorTileEntity = new ReplicatorTileEntity();
solarPanelTileEntity = new SolarPanelTileEntity();
@ -127,7 +127,7 @@ public class ProspectBlocks
GameRegistry.registerTileEntity(pressTileEntity.getClass(),"prospect:pressTileEntity");
GameRegistry.registerTileEntity(extruderTileEntity.getClass(),"prospect:extruderTileEntity");
GameRegistry.registerTileEntity(purifierTileEntity.getClass(), "prospect:purifierTileEntity");
GameRegistry.registerTileEntity(printerTileEntity.getClass(), "prospect:printerTileEntity");
GameRegistry.registerTileEntity(fabricatorTileEntity.getClass(), "prospect:fabricatorTileEntity");
GameRegistry.registerTileEntity(quarryTileEntity.getClass(), "prospect:quarryTileEntity");
GameRegistry.registerTileEntity(replicatorTileEntity.getClass(), "prospect:replicatorTileEntity");
GameRegistry.registerTileEntity(solarPanelTileEntity.getClass(), "prospect:solarPanelTileEntity");
@ -147,7 +147,7 @@ public class ProspectBlocks
event.getRegistry().registerAll(quarry_frame);
event.getRegistry().registerAll(quarry_tube);
event.getRegistry().registerAll(quarry_drill);
event.getRegistry().registerAll(printer);
event.getRegistry().registerAll(fabricator);
event.getRegistry().registerAll(replicator);
event.getRegistry().registerAll(launch_pad);
event.getRegistry().registerAll(capsule);
@ -180,7 +180,7 @@ public class ProspectBlocks
event.getRegistry().registerAll(new ItemBlock(press).setRegistryName(press.getRegistryName()));
event.getRegistry().registerAll(new ItemBlock(living_ore).setRegistryName(living_ore.getRegistryName()));
event.getRegistry().registerAll(new ItemBlock(purifier).setRegistryName(purifier.getRegistryName()));
event.getRegistry().registerAll(new ItemBlock(printer).setRegistryName(printer.getRegistryName()));
event.getRegistry().registerAll(new ItemBlock(fabricator).setRegistryName(fabricator.getRegistryName()));
event.getRegistry().registerAll(new ItemBlock(replicator).setRegistryName(replicator.getRegistryName()));
event.getRegistry().registerAll(new ItemBlock(quarry).setRegistryName(quarry.getRegistryName()));
event.getRegistry().registerAll(new ItemBlock(quarry_frame).setRegistryName(quarry_frame.getRegistryName()));
@ -221,7 +221,7 @@ public class ProspectBlocks
registerRender(Item.getItemFromBlock(quarry_frame));
registerRender(Item.getItemFromBlock(quarry_tube));
registerRender(Item.getItemFromBlock(quarry_drill));
registerRender(Item.getItemFromBlock(printer));
registerRender(Item.getItemFromBlock(fabricator));
registerRender(Item.getItemFromBlock(replicator));
registerRender(Item.getItemFromBlock(launch_pad));
registerRender(Item.getItemFromBlock(capsule));

View File

@ -76,7 +76,7 @@ public class ProspectItems
public static Item suit_schematic;
public static Item pants_schematic;
public static Item boots_schematic;
public static Item printer_schematic;
public static Item fabricator_schematic;
public static Item quarry_schematic;
public static Item purifier_schematic;
public static Item launch_pad_schematic;
@ -148,7 +148,7 @@ public class ProspectItems
helmet_schematic = new Schematic("helmet_schematic",3).setCreativeTab(Prospect.tabProspect).setMaxStackSize(64);
filter_schematic = new Schematic("filter_schematic",4).setCreativeTab(Prospect.tabProspect).setMaxStackSize(64);
launch_pad_schematic = new Schematic("launch_pad_schematic",5).setCreativeTab(Prospect.tabProspect).setMaxStackSize(64);
printer_schematic = new Schematic("printer_schematic",6).setCreativeTab(Prospect.tabProspect).setMaxStackSize(64);
fabricator_schematic = new Schematic("fabricator_schematic",6).setCreativeTab(Prospect.tabProspect).setMaxStackSize(64);
extruder_schematic = new Schematic("extruder_schematic",7).setCreativeTab(Prospect.tabProspect).setMaxStackSize(64);
purifier_schematic = new Schematic("purifier_schematic",8).setCreativeTab(Prospect.tabProspect).setMaxStackSize(64);
quarry_schematic = new Schematic("quarry_schematic",9).setCreativeTab(Prospect.tabProspect).setMaxStackSize(64);
@ -232,7 +232,7 @@ public class ProspectItems
event.getRegistry().registerAll(purifier_schematic);
event.getRegistry().registerAll(launch_pad_schematic);
event.getRegistry().registerAll(printer_schematic);
event.getRegistry().registerAll(fabricator_schematic);
event.getRegistry().registerAll(helmet_schematic);
event.getRegistry().registerAll(suit_schematic);
event.getRegistry().registerAll(pants_schematic);
@ -328,7 +328,7 @@ public class ProspectItems
registerRender(extruder_schematic);
registerRender(purifier_schematic);
registerRender(launch_pad_schematic);
registerRender(printer_schematic);
registerRender(fabricator_schematic);
registerRender(lv_transformer_schematic);
registerRender(mv_transformer_schematic);
registerRender(hv_transformer_schematic);

View File

@ -9,7 +9,7 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries;
@Mod.EventBusSubscriber(modid = Prospect.MODID)
public class ProspectSounds
{
static ResourceLocation printerSoundLocation;
static ResourceLocation fabricatorSoundLocation;
static ResourceLocation purifierSoundLocation;
static ResourceLocation quarrySoundLocation;
static ResourceLocation replicatorSoundLocation;
@ -17,7 +17,7 @@ public class ProspectSounds
static ResourceLocation capsuleSoundLocation;
static ResourceLocation extruderSoundLocation;
static ResourceLocation pressSoundLocation;
public static SoundEvent printerSoundEvent;
public static SoundEvent fabricatorSoundEvent;
public static SoundEvent purifierSoundEvent;
public static SoundEvent quarrySoundEvent;
public static SoundEvent replicatorSoundEvent;
@ -28,7 +28,7 @@ public class ProspectSounds
public static void init()
{
printerSoundLocation = new ResourceLocation("prospect", "printer");
fabricatorSoundLocation = new ResourceLocation("prospect", "fabricator");
purifierSoundLocation = new ResourceLocation("prospect", "purifier");
quarrySoundLocation = new ResourceLocation("prospect", "quarry");
replicatorSoundLocation = new ResourceLocation("prospect", "replicator");
@ -36,7 +36,7 @@ public class ProspectSounds
capsuleSoundLocation = new ResourceLocation("prospect", "capsule");
extruderSoundLocation = new ResourceLocation("prospect", "extruder");
pressSoundLocation = new ResourceLocation("prospect", "press");
printerSoundEvent = new SoundEvent(printerSoundLocation);
fabricatorSoundEvent = new SoundEvent(fabricatorSoundLocation);
purifierSoundEvent = new SoundEvent(purifierSoundLocation);
quarrySoundEvent = new SoundEvent(quarrySoundLocation);
replicatorSoundEvent = new SoundEvent(replicatorSoundLocation);

View File

@ -10,7 +10,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class PrinterContainer extends Container
public class FabricatorContainer extends Container
{
private final IInventory tilePrinter;
private int printTime;
@ -18,7 +18,7 @@ public class PrinterContainer extends Container
private int energyCapacity;
private int energyStored;
public PrinterContainer(InventoryPlayer playerInventory, IInventory printerInventory)
public FabricatorContainer(InventoryPlayer playerInventory, IInventory printerInventory)
{
this.tilePrinter = printerInventory;
this.addSlotToContainer(new Slot(printerInventory, 0, 56, 17));

View File

@ -44,7 +44,7 @@ public class Schematic extends ProspectItem
}
if (id == 6)
{
return new ItemStack(ProspectBlocks.printer);
return new ItemStack(ProspectBlocks.fabricator);
}
if (id == 7)
{

View File

@ -103,7 +103,7 @@ public class PotionSpore extends PotionProspect
public void performEffect(@Nonnull EntityLivingBase living, int amplified)
{
EntityPlayer player = (EntityPlayer) living;
if (player != null && ConfigHandler.getSporesEnabled())
if (player != null && ConfigHandler.toxicSporesEnabled())
{
boolean isPoisoned = false;
boolean nearPurifier = false;

View File

@ -1,26 +1,19 @@
package com.droog71.prospect.tilentity;
import com.droog71.prospect.fe.ProspectEnergyStorage;
import com.droog71.prospect.init.ProspectBlocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ITickable;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
public class CableTileEntity extends TileEntity implements ITickable
{
private ProspectEnergyStorage energyStorage = new ProspectEnergyStorage();
private int rating;
private int capacity;
public CableTileEntity()
{
@ -28,12 +21,39 @@ public class CableTileEntity extends TileEntity implements ITickable
}
public CableTileEntity(int rating, int capacity)
{
{
this.rating = rating;
this.capacity = capacity;
}
@Override
public void onLoad()
{
energyStorage.maxReceive = rating;
energyStorage.capacity = capacity;
this.rating = rating;
}
@Override
public void invalidate()
{
super.invalidate(); // this is important for mc!
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
rating = tag.getInteger("rating");
capacity = tag.getInteger("capacity");
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tag)
{
tag.setInteger("rating", rating);
tag.setInteger("capacity", capacity);
return tag;
}
@Override
public void update()
{
@ -41,72 +61,17 @@ public class CableTileEntity extends TileEntity implements ITickable
{
if (energyStorage.overloaded)
{
explode();
energyStorage.explode(world,pos);
}
else
{
giveEnergy();
for (IEnergyStorage sink : energyStorage.receivers(world, pos))
{
energyStorage.giveEnergy(energyStorage, sink, rating);
}
}
}
}
private void giveEnergy()
{
BlockPos[] sides = {pos.add(0,1,0),pos.add(1,0,0),pos.add(0,0,1),pos.add(0,-1,0),pos.add(-1,0,0),pos.add(0,0,-1)};
for (BlockPos p : sides) //Iterate over all adjacent blocks.
{
TileEntity otherTile = world.getTileEntity(p);
if (otherTile != null) //TileEntity exists at adjacent block position.
{
EnumFacing direction = null;
for (EnumFacing facing : EnumFacing.VALUES)
{
IEnergyStorage otherStorage = otherTile.getCapability(CapabilityEnergy.ENERGY,facing);
if (otherStorage != null) //The TileEntity has the required forge energy capability.
{
if (direction == null)
{
direction = facing; //The cable will transfer energy in this direction if possible.
}
}
}
IEnergyStorage otherStorage = otherTile.getCapability(CapabilityEnergy.ENERGY,direction);
if (otherStorage != null)
{
if (energyStorage.getEnergyStored() > 0) //The cable has the potential to transfer energy to the adjacent block.
{
if (otherStorage.canReceive()) //The adjacent block can receive the energy.
{
if (otherStorage.getEnergyStored() < energyStorage.getEnergyStored()) //Potential exists between the two energy storage instances.
{
int potential = (energyStorage.getEnergyStored() - otherStorage.getEnergyStored())/2; //Calculate the potential.
int output = Math.min(potential, rating); //If potential is greater than this cable's maximum transfer rate, use the lower value.
energyStorage.useEnergy(output); //Remove energy from this cable.
otherStorage.receiveEnergy(rating, true); //Simulate the transfer. If this transaction overloads the receiver, it will explode.
if (otherStorage != null) //Recipient did not explode.
{
otherStorage.receiveEnergy(output,false); //Add the energy to the adjacent block.
}
}
}
}
}
}
}
}
private void explode()
{
world.playSound(null, pos, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 0.5f, 1);
WorldServer w = (WorldServer) world;
w.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, pos.getX(), pos.getY(), pos.getZ(), 1, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.LAVA, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.FLAME, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
world.getBlockState(pos).getBlock().breakBlock(world, pos, ProspectBlocks.extruder.getDefaultState());
EntityItem item = new EntityItem(w, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ProspectBlocks.extruder));
w.spawnEntity(item);
world.setBlockToAir(pos);
}
@Override
public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @javax.annotation.Nullable net.minecraft.util.EnumFacing facing)

View File

@ -1,16 +1,13 @@
package com.droog71.prospect.tilentity;
import com.droog71.prospect.fe.ProspectEnergyStorage;
import com.droog71.prospect.init.ProspectBlocks;
import com.droog71.prospect.init.ProspectItems;
import com.droog71.prospect.init.ProspectSounds;
import com.droog71.prospect.inventory.ExtruderContainer;
import ic2.api.energy.prefab.BasicSink;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
@ -19,17 +16,16 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;
public class ExtruderTileEntity extends TileEntity implements ITickable, ISidedInventory
{
@ -267,7 +263,7 @@ public class ExtruderTileEntity extends TileEntity implements ITickable, ISidedI
{
if (energyStorage.overloaded)
{
explode();
energyStorage.explode(world,pos);
}
else
{
@ -294,19 +290,6 @@ public class ExtruderTileEntity extends TileEntity implements ITickable, ISidedI
}
}
private void explode()
{
world.playSound(null, pos, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 0.5f, 1);
WorldServer w = (WorldServer) world;
w.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, pos.getX(), pos.getY(), pos.getZ(), 1, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.LAVA, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.FLAME, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
world.getBlockState(pos).getBlock().breakBlock(world, pos, ProspectBlocks.extruder.getDefaultState());
EntityItem item = new EntityItem(w, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ProspectBlocks.extruder));
w.spawnEntity(item);
world.setBlockToAir(pos);
}
private void doWork()
{
boolean flag1 = false;
@ -386,17 +369,30 @@ public class ExtruderTileEntity extends TileEntity implements ITickable, ISidedI
return false;
}
public int getextrudeTime(ItemStack stack)
public int getextrudeTime(ItemStack stack) //Could be used for varying extrude time for different ingots.
{
return 200;
return 100;
}
private boolean isCopperIngot(ItemStack stack)
{
NonNullList<ItemStack> copper = OreDictionary.getOres("ingotCopper");
for (ItemStack s : copper)
{
if (s.getItem().getRegistryName() == stack.getItem().getRegistryName())
{
return true;
}
}
return false;
}
/**
* Returns true if the extruder can extrude an item, i.e. has a source item, destination stack isn't full, etc.
*/
private boolean canExtrude()
{
if (extruderItemStacks.get(0).isEmpty() || extruderItemStacks.get(0).getItem() != ProspectItems.copper_ingot)
if (extruderItemStacks.get(0).isEmpty() || !isCopperIngot(extruderItemStacks.get(0)))
{
return false;
}

View File

@ -4,19 +4,16 @@ import java.util.ArrayList;
import java.util.List;
import com.droog71.prospect.fe.ProspectEnergyStorage;
import com.droog71.prospect.init.ProspectBlocks;
import com.droog71.prospect.init.ProspectSounds;
import com.droog71.prospect.inventory.PrinterContainer;
import com.droog71.prospect.inventory.FabricatorContainer;
import com.droog71.prospect.items.Schematic;
import ic2.api.energy.prefab.BasicSink;
import net.minecraft.block.Block;
import net.minecraft.block.BlockChest;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
@ -28,7 +25,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.EntitySelectors;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundCategory;
@ -36,19 +32,18 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class PrinterTileEntity extends TileEntity implements ITickable, ISidedInventory
public class FabricatorTileEntity extends TileEntity implements ITickable, 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};
private NonNullList<ItemStack> printerItemStacks = NonNullList.<ItemStack>withSize(3, ItemStack.EMPTY);
private NonNullList<ItemStack> fabricatorItemStacks = NonNullList.<ItemStack>withSize(3, ItemStack.EMPTY);
private int energyStored;
private int energyCapacity;
private int printTime;
@ -104,13 +99,13 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
@Override
public int getSizeInventory()
{
return printerItemStacks.size();
return fabricatorItemStacks.size();
}
@Override
public boolean isEmpty()
{
for (ItemStack itemstack : printerItemStacks)
for (ItemStack itemstack : fabricatorItemStacks)
{
if (!itemstack.isEmpty())
{
@ -127,7 +122,7 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
@Override
public ItemStack getStackInSlot(int index)
{
return printerItemStacks.get(index);
return fabricatorItemStacks.get(index);
}
/**
@ -136,7 +131,7 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
@Override
public ItemStack decrStackSize(int index, int count)
{
return ItemStackHelper.getAndSplit(printerItemStacks, index, count);
return ItemStackHelper.getAndSplit(fabricatorItemStacks, index, count);
}
/**
@ -145,7 +140,7 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
@Override
public ItemStack removeStackFromSlot(int index)
{
return ItemStackHelper.getAndRemove(printerItemStacks, index);
return ItemStackHelper.getAndRemove(fabricatorItemStacks, index);
}
/**
@ -154,9 +149,9 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
@Override
public void setInventorySlotContents(int index, ItemStack stack)
{
ItemStack itemstack = printerItemStacks.get(index);
ItemStack itemstack = fabricatorItemStacks.get(index);
boolean flag = !stack.isEmpty() && stack.isItemEqual(itemstack) && ItemStack.areItemStackTagsEqual(stack, itemstack);
printerItemStacks.set(index, stack);
fabricatorItemStacks.set(index, stack);
if (stack.getCount() > getInventoryStackLimit())
{
@ -198,8 +193,8 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
printerItemStacks = NonNullList.<ItemStack>withSize(getSizeInventory(), ItemStack.EMPTY);
ItemStackHelper.loadAllItems(compound, printerItemStacks);
fabricatorItemStacks = NonNullList.<ItemStack>withSize(getSizeInventory(), ItemStack.EMPTY);
ItemStackHelper.loadAllItems(compound, fabricatorItemStacks);
energyStored = compound.getInteger("EnergyStored");
printTime = compound.getInteger("PrintTime");
totalPrintTime = compound.getInteger("PrintTimeTotal");
@ -222,7 +217,7 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
compound.setInteger("EnergyCapacity", (short)energyCapacity);
compound.setInteger("PrintTime", (short)printTime);
compound.setInteger("PrintTimeTotal", (short)totalPrintTime);
ItemStackHelper.saveAllItems(compound, printerItemStacks);
ItemStackHelper.saveAllItems(compound, fabricatorItemStacks);
if (Loader.isModLoaded("ic2"))
{
if ((BasicSink) ic2EnergySink == null)
@ -281,7 +276,7 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
{
if (energyStorage.overloaded)
{
explode();
energyStorage.explode(world,pos);
}
else
{
@ -308,7 +303,7 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
if (printTime == totalPrintTime)
{
printTime = 0;
totalPrintTime = getPrintTime(printerItemStacks.get(0));
totalPrintTime = getPrintTime(fabricatorItemStacks.get(0));
printItem();
flag1 = true;
}
@ -321,24 +316,11 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
effectsTimer++;
if (effectsTimer > 40)
{
world.playSound(null, pos, ProspectSounds.printerSoundEvent, SoundCategory.BLOCKS, 0.25f, 1);
world.playSound(null, pos, ProspectSounds.fabricatorSoundEvent, SoundCategory.BLOCKS, 0.25f, 1);
effectsTimer = 0;
}
}
private void explode()
{
world.playSound(null, pos, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 0.5f, 1);
WorldServer w = (WorldServer) world;
w.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, pos.getX(), pos.getY(), pos.getZ(), 1, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.LAVA, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.FLAME, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
world.getBlockState(pos).getBlock().breakBlock(world, pos, ProspectBlocks.extruder.getDefaultState());
EntityItem item = new EntityItem(w, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ProspectBlocks.extruder));
w.spawnEntity(item);
world.setBlockToAir(pos);
}
private void updateEnergy()
{
if (energyStorage.getEnergyStored() > 0)
@ -395,7 +377,7 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
public int getPrintTime(ItemStack stack)
{
return 200;
return 100;
}
private boolean canCraft(ItemStack[] stacks, IInventory iinventory)
@ -520,17 +502,17 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
}
/**
* Returns true if the printer can print an item, i.e. has a source item, destination stack isn't full, etc.
* Returns true if the fabricator can print an item, i.e. has a source item, destination stack isn't full, etc.
*/
private boolean canPrint()
{
if (printerItemStacks.get(0).isEmpty() || !(printerItemStacks.get(0).getItem() instanceof Schematic))
if (fabricatorItemStacks.get(0).isEmpty() || !(fabricatorItemStacks.get(0).getItem() instanceof Schematic))
{
return false;
}
ItemStack itemstack = null;
Item item = printerItemStacks.get(0).getItem();
Item item = fabricatorItemStacks.get(0).getItem();
ItemStack[] required = ((Schematic) item).getIngredients();
ItemStack result = ((Schematic) item).getResult();
@ -546,7 +528,7 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
return false;
}
ItemStack itemstack1 = printerItemStacks.get(2);
ItemStack itemstack1 = fabricatorItemStacks.get(2);
if (itemstack1.isEmpty())
{
@ -572,7 +554,7 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
{
ItemStack itemstack1 = new ItemStack(Items.AIR);
Item item = printerItemStacks.get(0).getItem();
Item item = fabricatorItemStacks.get(0).getItem();
if (item instanceof Schematic)
{
@ -588,11 +570,11 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
}
}
ItemStack itemstack2 = printerItemStacks.get(2);
ItemStack itemstack2 = fabricatorItemStacks.get(2);
if (itemstack2.isEmpty())
{
printerItemStacks.set(2, itemstack1.copy());
fabricatorItemStacks.set(2, itemstack1.copy());
}
else if (itemstack2.getItem() == itemstack1.getItem())
{
@ -687,7 +669,7 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
{
return new PrinterContainer(playerInventory, this);
return new FabricatorContainer(playerInventory, this);
}
@Override
@ -736,7 +718,7 @@ public class PrinterTileEntity extends TileEntity implements ITickable, ISidedIn
@Override
public void clear()
{
printerItemStacks.clear();
fabricatorItemStacks.clear();
}
net.minecraftforge.items.IItemHandler handlerTop = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.UP);

View File

@ -7,10 +7,8 @@ import com.droog71.prospect.init.ProspectSounds;
import com.droog71.prospect.inventory.LaunchPadContainer;
import ic2.api.energy.prefab.BasicSink;
import ic2.core.platform.registry.Ic2Items;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
@ -37,9 +35,8 @@ import techguns.TGItems;
public class LaunchPadTileEntity extends TileEntity implements ITickable, 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};
private static final int[] SLOTS_BOTTOM = new int[] {2};
private static final int[] SLOTS_SIDES = new int[] {0};
private NonNullList<ItemStack> launchPadItemStacks = NonNullList.<ItemStack>withSize(3, ItemStack.EMPTY);
private int energyStored;
private int energyCapacity;
@ -264,19 +261,6 @@ public class LaunchPadTileEntity extends TileEntity implements ITickable, ISided
{
return inventory.getField(0) > 0;
}
private void explode()
{
world.playSound(null, pos, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 0.5f, 1);
WorldServer w = (WorldServer) world;
w.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, pos.getX(), pos.getY(), pos.getZ(), 1, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.LAVA, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.FLAME, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
world.getBlockState(pos).getBlock().breakBlock(world, pos, ProspectBlocks.extruder.getDefaultState());
EntityItem item = new EntityItem(w, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ProspectBlocks.extruder));
w.spawnEntity(item);
world.setBlockToAir(pos);
}
/**
* Like the old updateEntity(), except more generic.
@ -288,7 +272,7 @@ public class LaunchPadTileEntity extends TileEntity implements ITickable, ISided
{
if (energyStorage.overloaded)
{
explode();
energyStorage.explode(world,pos);
}
else
{
@ -424,9 +408,9 @@ public class LaunchPadTileEntity extends TileEntity implements ITickable, ISided
return false;
}
public int getlaunchTime(ItemStack stack)
public int getlaunchTime(ItemStack stack) //Could be used to vary launch times depending on the item.
{
return 1000;
return 100;
}
private int getCurrentPayout()
@ -499,34 +483,34 @@ public class LaunchPadTileEntity extends TileEntity implements ITickable, ISided
}
}
if (item == Item.getItemFromBlock(ProspectBlocks.replicator) || item == Item.getItemFromBlock(ProspectBlocks.iv_solar_panel))
{
currentPayout = 64;
return currentPayout;
}
if (item == Item.getItemFromBlock(ProspectBlocks.quarry) || item == Item.getItemFromBlock(ProspectBlocks.ev_solar_panel) || item == Item.getItemFromBlock(ProspectBlocks.purifier) || item == Item.getItemFromBlock(ProspectBlocks.fabricator))
{
currentPayout = 32;
return currentPayout;
}
if (item == Item.getItemFromBlock(ProspectBlocks.quarry) || item == Item.getItemFromBlock(ProspectBlocks.ev_solar_panel))
if (item == Item.getItemFromBlock(ProspectBlocks.hv_solar_panel) || item == Item.getItemFromBlock(ProspectBlocks.ev_transformer))
{
currentPayout = 16;
return currentPayout;
}
if (item == Item.getItemFromBlock(ProspectBlocks.hv_solar_panel) || item == Item.getItemFromBlock(ProspectBlocks.printer) || item == Item.getItemFromBlock(ProspectBlocks.ev_transformer) || item == Item.getItemFromBlock(ProspectBlocks.iv_cable))
if (item == Item.getItemFromBlock(ProspectBlocks.mv_solar_panel) || item == Item.getItemFromBlock(ProspectBlocks.hv_transformer) || item == Item.getItemFromBlock(ProspectBlocks.iv_cable))
{
currentPayout = 8;
return currentPayout;
}
if (item == Item.getItemFromBlock(ProspectBlocks.purifier) || item == Item.getItemFromBlock(ProspectBlocks.hv_transformer) || item == Item.getItemFromBlock(ProspectBlocks.ev_cable) || item == ProspectItems.in_iv_wire)
if (item == Item.getItemFromBlock(ProspectBlocks.extruder) || item == Item.getItemFromBlock(ProspectBlocks.press) || item == Item.getItemFromBlock(ProspectBlocks.lv_solar_panel) || item == Item.getItemFromBlock(ProspectBlocks.hv_cable) || item == Item.getItemFromBlock(ProspectBlocks.mv_transformer) || item == ProspectItems.in_iv_wire)
{
currentPayout = 4;
return currentPayout;
}
if (item == Item.getItemFromBlock(ProspectBlocks.extruder) || item == Item.getItemFromBlock(ProspectBlocks.press) || item == Item.getItemFromBlock(ProspectBlocks.lv_solar_panel) || item == Item.getItemFromBlock(ProspectBlocks.hv_cable) || item == Item.getItemFromBlock(ProspectBlocks.mv_transformer) || item == ProspectItems.in_ev_wire)
if (item == Item.getItemFromBlock(ProspectBlocks.lv_cable) || item == Item.getItemFromBlock(ProspectBlocks.lv_transformer) || item == Item.getItemFromBlock(ProspectBlocks.mv_cable) || item == ProspectItems.in_ev_wire || item == ProspectItems.in_hv_wire || item == ProspectItems.in_mv_wire || item == ProspectItems.in_lv_wire || item == ProspectItems.quantum_circuit || item == ProspectItems.gem)
{
currentPayout = 2;
return currentPayout;
}
if (item == Item.getItemFromBlock(ProspectBlocks.lv_cable) || item == Item.getItemFromBlock(ProspectBlocks.mv_cable) || item == ProspectItems.in_hv_wire || item == ProspectItems.in_mv_wire || item == ProspectItems.in_lv_wire || item == ProspectItems.quantum_circuit || item == ProspectItems.gem)
{
currentPayout = 1;
return currentPayout;
}
return 0;
}
@ -650,7 +634,7 @@ public class LaunchPadTileEntity extends TileEntity implements ITickable, ISided
}
else
{
return side == EnumFacing.UP ? SLOTS_TOP : SLOTS_SIDES;
return SLOTS_SIDES;
}
}

View File

@ -1,15 +1,12 @@
package com.droog71.prospect.tilentity;
import com.droog71.prospect.fe.ProspectEnergyStorage;
import com.droog71.prospect.init.ProspectBlocks;
import com.droog71.prospect.init.ProspectItems;
import com.droog71.prospect.init.ProspectSounds;
import com.droog71.prospect.inventory.PressContainer;
import ic2.api.energy.prefab.BasicSink;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
@ -18,12 +15,10 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.fml.common.Loader;
@ -267,7 +262,7 @@ public class PressTileEntity extends TileEntity implements ITickable, ISidedInve
{
if (energyStorage.overloaded)
{
explode();
energyStorage.explode(world,pos);
}
else
{
@ -294,19 +289,6 @@ public class PressTileEntity extends TileEntity implements ITickable, ISidedInve
}
}
private void explode()
{
world.playSound(null, pos, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 0.5f, 1);
WorldServer w = (WorldServer) world;
w.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, pos.getX(), pos.getY(), pos.getZ(), 1, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.LAVA, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.FLAME, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
world.getBlockState(pos).getBlock().breakBlock(world, pos, ProspectBlocks.press.getDefaultState());
EntityItem item = new EntityItem(w, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ProspectBlocks.press));
w.spawnEntity(item);
world.setBlockToAir(pos);
}
private void doWork()
{
boolean flag1 = false;
@ -386,9 +368,9 @@ public class PressTileEntity extends TileEntity implements ITickable, ISidedInve
return false;
}
public int getpressTime(ItemStack stack)
public int getpressTime(ItemStack stack) //Could be used for varying press time for different ingots.
{
return 200;
return 100;
}
private ItemStack getPlate(ItemStack stack)
@ -396,7 +378,7 @@ public class PressTileEntity extends TileEntity implements ITickable, ISidedInve
NonNullList<ItemStack> copper = OreDictionary.getOres("ingotCopper");
for (ItemStack s : copper)
{
if (s.getDisplayName() == stack.getDisplayName())
if (s.getItem().getRegistryName() == stack.getItem().getRegistryName())
{
return new ItemStack(ProspectItems.copper_plate);
}
@ -404,7 +386,7 @@ public class PressTileEntity extends TileEntity implements ITickable, ISidedInve
NonNullList<ItemStack> tin = OreDictionary.getOres("ingotTin");
for (ItemStack s : tin)
{
if (s.getDisplayName() == stack.getDisplayName())
if (s.getItem().getRegistryName() == stack.getItem().getRegistryName())
{
return new ItemStack(ProspectItems.tin_plate);
}
@ -412,7 +394,7 @@ public class PressTileEntity extends TileEntity implements ITickable, ISidedInve
NonNullList<ItemStack> silver = OreDictionary.getOres("ingotSilver");
for (ItemStack s : silver)
{
if (s.getDisplayName() == stack.getDisplayName())
if (s.getItem().getRegistryName() == stack.getItem().getRegistryName())
{
return new ItemStack(ProspectItems.silver_plate);
}
@ -420,7 +402,7 @@ public class PressTileEntity extends TileEntity implements ITickable, ISidedInve
NonNullList<ItemStack> lead = OreDictionary.getOres("ingotLead");
for (ItemStack s : lead)
{
if (s.getDisplayName() == stack.getDisplayName())
if (s.getItem().getRegistryName() == stack.getItem().getRegistryName())
{
return new ItemStack(ProspectItems.lead_plate);
}
@ -428,7 +410,7 @@ public class PressTileEntity extends TileEntity implements ITickable, ISidedInve
NonNullList<ItemStack> aluminum = OreDictionary.getOres("ingotAluminum");
for (ItemStack s : aluminum)
{
if (s.getDisplayName() == stack.getDisplayName())
if (s.getItem().getRegistryName() == stack.getItem().getRegistryName())
{
return new ItemStack(ProspectItems.aluminum_plate);
}

View File

@ -3,8 +3,8 @@ package com.droog71.prospect.tilentity;
import java.util.Iterator;
import java.util.NoSuchElementException;
import com.droog71.prospect.blocks.energy.Purifier;
import com.droog71.prospect.config.ConfigHandler;
import com.droog71.prospect.fe.ProspectEnergyStorage;
import com.droog71.prospect.init.ProspectBlocks;
import com.droog71.prospect.init.ProspectSounds;
import ic2.api.energy.prefab.BasicSink;
import net.minecraft.util.EnumFacing;
@ -16,9 +16,6 @@ import net.minecraft.world.WorldServer;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.fml.common.Loader;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -106,7 +103,7 @@ public class PurifierTileEntity extends TileEntity implements ITickable
{
if (energyStorage.overloaded)
{
explode();
energyStorage.explode(world,pos);
}
else
{
@ -129,39 +126,29 @@ public class PurifierTileEntity extends TileEntity implements ITickable
effectsTimer++;
if (effectsTimer > 40)
{
WorldServer w = (WorldServer) world;
BlockPos corner_1 = pos.add(-20, -20, -20);
BlockPos corner_2 = pos.add(20, 20, 20);
Iterable<BlockPos> allBlocks = BlockPos.getAllInBox(corner_1, corner_2);
Iterator<BlockPos> iter = allBlocks.iterator();
while(iter.hasNext())
if (ConfigHandler.purifierParticleEffectsEnabled())
{
try
WorldServer w = (WorldServer) world;
BlockPos corner_1 = pos.add(-20, -20, -20);
BlockPos corner_2 = pos.add(20, 20, 20);
Iterable<BlockPos> allBlocks = BlockPos.getAllInBox(corner_1, corner_2);
Iterator<BlockPos> iter = allBlocks.iterator();
while(iter.hasNext())
{
w.spawnParticle(EnumParticleTypes.TOWN_AURA, iter.next().getX(), iter.next().getY(), iter.next().getZ(), 1, 0, 0, 0, 1, null);
}
catch(NoSuchElementException e)
{
//NOOP
try
{
w.spawnParticle(EnumParticleTypes.TOWN_AURA, iter.next().getX(), iter.next().getY(), iter.next().getZ(), 1, 0, 0, 0, 1, null);
}
catch(NoSuchElementException e)
{
//NOOP
}
}
}
world.playSound(null, pos, ProspectSounds.purifierSoundEvent, SoundCategory.BLOCKS, 0.25f, 1);
effectsTimer = 0;
}
}
private void explode()
{
world.playSound(null, pos, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 0.5f, 1);
WorldServer w = (WorldServer) world;
w.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, pos.getX(), pos.getY(), pos.getZ(), 1, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.LAVA, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.FLAME, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
world.getBlockState(pos).getBlock().breakBlock(world, pos, ProspectBlocks.extruder.getDefaultState());
EntityItem item = new EntityItem(w, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ProspectBlocks.extruder));
w.spawnEntity(item);
world.setBlockToAir(pos);
}
private boolean useEnergy()
{

View File

@ -29,7 +29,6 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
@ -48,10 +47,11 @@ public class QuarryTileEntity extends TileEntity implements ITickable
private boolean quarryFinished;
private boolean overflow;
private IInventory currentInventory;
private List<BlockPos> quarryPositions = new ArrayList<BlockPos>();
private int energyStored;
private boolean miningBlock;
private Object ic2EnergySink;
private ProspectEnergyStorage energyStorage = new ProspectEnergyStorage();
public List<BlockPos> quarryPositions = new ArrayList<BlockPos>();
@Override
public void onLoad()
@ -158,6 +158,7 @@ public class QuarryTileEntity extends TileEntity implements ITickable
return compound;
}
//Puts mined blocks and items into adjacent storage.
private void transferItemOut(ItemStack stack)
{
IInventory iinventory = getInventoryForTransfer();
@ -216,6 +217,7 @@ public class QuarryTileEntity extends TileEntity implements ITickable
}
}
//Checks if the block being mined is a liquid.
private boolean isLiquid(ItemStack stack)
{
Block b = Block.getBlockFromItem(stack.getItem());
@ -229,6 +231,7 @@ public class QuarryTileEntity extends TileEntity implements ITickable
}
}
//Checks if an itemstack can be combined with another.
private static boolean canCombine(ItemStack stack1, ItemStack stack2)
{
if (stack1.getItem() != stack2.getItem())
@ -249,6 +252,7 @@ public class QuarryTileEntity extends TileEntity implements ITickable
}
}
//Checks if given inventory is full.
private boolean isInventoryFull(IInventory inventoryIn)
{
if (inventoryIn instanceof ISidedInventory)
@ -271,6 +275,7 @@ public class QuarryTileEntity extends TileEntity implements ITickable
return true;
}
//Checks if given inventory has any empty slots.
private boolean inventoryHasEmptySlot(IInventory inventoryIn)
{
if (inventoryIn instanceof ISidedInventory)
@ -293,6 +298,7 @@ public class QuarryTileEntity extends TileEntity implements ITickable
return false;
}
//The adjacent inventory the quarry will use to transfer items out.
public IInventory getInventoryForTransfer()
{
List<IInventory> invList = new ArrayList<IInventory>();
@ -340,6 +346,7 @@ public class QuarryTileEntity extends TileEntity implements ITickable
return null;
}
//Returns instance of IInventory at a given position.
public static IInventory getInventoryAtPosition(World worldIn, double x, double y, double z)
{
IInventory iinventory = null;
@ -378,6 +385,7 @@ public class QuarryTileEntity extends TileEntity implements ITickable
return iinventory;
}
//Sets the starting position for the quarry.
private void initPos()
{
if (miningX == 100000000)
@ -390,6 +398,7 @@ public class QuarryTileEntity extends TileEntity implements ITickable
}
}
//Sound played when a block is mined.
private void playMiningSound(BlockPos p)
{
if (world.getBlockState(p).getBlock() != Blocks.AIR)
@ -398,95 +407,86 @@ public class QuarryTileEntity extends TileEntity implements ITickable
}
}
//Amount of energy stored.
private int getEnergyStored()
{
if (energyStorage.getEnergyStored() > 0)
{
if (Loader.isModLoaded("ic2"))
if (Loader.isModLoaded("ic2")) //If FE is in use, EU is disabled.
{
((BasicSink) ic2EnergySink).setEnergyStored(0);
((BasicSink) ic2EnergySink).setCapacity(0);
}
energyStored = energyStorage.getEnergyStored()/4;
energyStored = energyStorage.getEnergyStored()/4; //Return FE scaled to EU equivalent.
}
else
{
if (Loader.isModLoaded("ic2"))
{
((BasicSink) ic2EnergySink).setCapacity(400000);
((BasicSink) ic2EnergySink).setCapacity(400000); //FE is not in use, IC2 is installed, so EU is enabled.
if (((BasicSink) ic2EnergySink).getEnergyStored() > 0)
{
energyStored = (int) ((BasicSink) ic2EnergySink).getEnergyStored();
energyStored = (int) ((BasicSink) ic2EnergySink).getEnergyStored(); //Return EU stored.
}
}
}
return energyStored;
}
//Attempts to consume energy and returns true if successful.
private boolean useEnergy(int amount)
{
if (Loader.isModLoaded("ic2"))
{
if (((BasicSink) ic2EnergySink).useEnergy(amount))
if (((BasicSink) ic2EnergySink).useEnergy(amount)) //Attempt to consume EU.
{
return true;
}
else if (energyStorage != null)
{
if (energyStorage.getEnergyStored() >= amount)
if (energyStorage.getEnergyStored() >= amount*4)
{
energyStorage.useEnergy(amount*4);
energyStorage.useEnergy(amount*4); //Attempt to consume FE.
return true;
}
}
}
else if (energyStorage != null)
{
if (energyStorage.getEnergyStored() >= amount)
if (energyStorage.getEnergyStored() >= amount*4)
{
energyStorage.useEnergy(amount*4);
energyStorage.useEnergy(amount*4); //Attempt to consume FE.
return true;
}
}
return false;
}
private void explode()
{
world.playSound(null, pos, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 0.5f, 1);
WorldServer w = (WorldServer) world;
w.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, pos.getX(), pos.getY(), pos.getZ(), 1, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.LAVA, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.FLAME, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
world.getBlockState(pos).getBlock().breakBlock(world, pos, ProspectBlocks.extruder.getDefaultState());
EntityItem item = new EntityItem(w, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ProspectBlocks.extruder));
w.spawnEntity(item);
world.setBlockToAir(pos);
}
@Override
public void update()
{
if (!world.isRemote) // Everything is done on the server
if (!world.isRemote) //Everything is done on the server
{
if (energyStorage.overloaded)
{
explode();
energyStorage.explode(world,pos);
}
else
{
if (quarryFinished == false)
if (quarryFinished == false) //The quarry has not hit bedrock.
{
if (getEnergyStored() >= 5)
if (getEnergyStored() > 0)
{
soundTimer++;
if (soundTimer >= 60)
{
//Looping sound effect played at the quarry block.
world.playSound(null, pos, ProspectSounds.quarrySoundEvent, SoundCategory.BLOCKS, 1.0f, 1);
soundTimer = 0;
}
}
//Speed of quarry scales with the amount of power received.
if (getEnergyStored() >= 1024)
{
useEnergy(1024);
@ -520,28 +520,30 @@ public class QuarryTileEntity extends TileEntity implements ITickable
if (quarryTimer >= 32)
{
initPos();
if (miningX < pos.getX() + 11)
if (miningX < pos.getX() + 11) //After one row on the Z axis is mined, X position will increase.
{
if (miningZ < pos.getZ() + 11)
if (miningZ < pos.getZ() + 11) //Mines one block per tick until a row along the Z axis is complete.
{
BlockPos p = new BlockPos(miningX,pos.getY()-level,miningZ);
BlockPos p = new BlockPos(miningX,pos.getY()-level,miningZ); //Level variable controls depth.
Block b = world.getBlockState(p).getBlock();
if (b != Blocks.BEDROCK)
if (b != Blocks.BEDROCK) //Quarry stops when it hits bedrock.
{
ItemStack stack = new ItemStack(Items.AIR);
Item itemDropped = b.getItemDropped(b.getDefaultState(), new Random(), 0);
if (itemDropped != Item.getItemFromBlock(b))
{
stack = new ItemStack(itemDropped);
stack = new ItemStack(itemDropped); //Used for blocks that drop items; diamonds, coal, etc.
}
else
{
stack = new ItemStack(Item.getItemFromBlock(b));
}
stack = new ItemStack(Item.getItemFromBlock(b)); //All other blocks.
}
if (stack.getItem() != Items.AIR)
{
transferItemOut(stack); //Put the item collected in an adjacent storage container.
}
transferItemOut(stack);
if (level == 1)
if (level == 1) //Builds the quarry frame and tube 1 block below the quarry.
{
if (p.getX() == pos.getX() && p.getZ() == pos.getZ())
{
@ -584,62 +586,66 @@ public class QuarryTileEntity extends TileEntity implements ITickable
}
else
{
if (level == 2)
if (level == 2) //Prevents the frame on level 1 from being destroyed by the quarry.
{
if (p.getX() != pos.getX() && p.getZ() != pos.getZ())
{
if (p.getX() != pos.getX() - 10 && p.getX() != pos.getX() + 10 && p.getZ() != pos.getZ() - 10 && p.getZ() != pos.getZ() + 10)
{
world.setBlockToAir(p.add(0,1,0));
miningBlock = true; //A block will be removed at this position.
}
else
{
miningBlock = false;
}
}
}
else
{
world.setBlockToAir(p.add(0,1,0));
miningBlock = true; //A block will be removed at this position.
if (world.getBlockState(p).getBlock() != Blocks.AIR)
{
//Play sound and spawn particles at each block mined.
playMiningSound(p);
WorldServer w = (WorldServer) world;
w.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, p.getX(), p.getY(), p.getZ(), 1, 0, 0, 0, 1, null);
}
}
world.setBlockToAir(p);
world.setBlockState(p, ProspectBlocks.quarry_drill.getDefaultState());
world.setBlockState(p, ProspectBlocks.quarry_drill.getDefaultState()); //Move the drill down to the next level.
world.getBlockState(p).getBlock().setHardness(1000.0f);
quarryPositions.add(p);
}
quarryPositions.add(p);
if (miningBlock == true)
{
//Remove the old drill block.
world.setBlockToAir(p.add(0,1,0));
miningBlock = false;
}
}
}
}
else
{
quarryFinished = true;
quarryFinished = true; //The quarry hit bedrock.
}
miningZ++;
}
else
{
miningZ = pos.getZ() - 10;
//Reset the Z axis position and move on to the next row on the X axis.
miningZ = pos.getZ() - 10;
miningX++;
}
}
else
{
world.playSound(null, pos, ProspectSounds.quarrySoundEvent, SoundCategory.BLOCKS, 1.0f, 1);
miningX = pos.getX() - 10;
//Reset the X axis position and increase depth to move to the next layer.
miningX = pos.getX() - 10;
level++;
markDirty();
}
}
quarryTimer = 0;
}
}
else
{
for (BlockPos p : quarryPositions)
{
world.getBlockState(p).getBlock().setHardness(1.0f);
}
}
}
}
}
}

View File

@ -1,18 +1,15 @@
package com.droog71.prospect.tilentity;
import com.droog71.prospect.fe.ProspectEnergyStorage;
import com.droog71.prospect.init.ProspectBlocks;
import com.droog71.prospect.init.ProspectItems;
import com.droog71.prospect.init.ProspectSounds;
import com.droog71.prospect.inventory.ReplicatorContainer;
import ic2.api.energy.prefab.BasicSink;
import ic2.core.platform.registry.Ic2Items;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
@ -22,11 +19,9 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.fml.common.Loader;
@ -290,7 +285,7 @@ public class ReplicatorTileEntity extends TileEntity implements ITickable, ISide
{
if (energyStorage.overloaded)
{
explode();
energyStorage.explode(world,pos);
}
else
{
@ -348,19 +343,6 @@ public class ReplicatorTileEntity extends TileEntity implements ITickable, ISide
}
}
private void explode()
{
world.playSound(null, pos, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 0.5f, 1);
WorldServer w = (WorldServer) world;
w.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, pos.getX(), pos.getY(), pos.getZ(), 1, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.LAVA, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.FLAME, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
world.getBlockState(pos).getBlock().breakBlock(world, pos, ProspectBlocks.extruder.getDefaultState());
EntityItem item = new EntityItem(w, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ProspectBlocks.extruder));
w.spawnEntity(item);
world.setBlockToAir(pos);
}
private void updateEnergy()
{
if (energyStorage.getEnergyStored() > 0)
@ -420,16 +402,16 @@ public class ReplicatorTileEntity extends TileEntity implements ITickable, ISide
Item i = stack.getItem();
if (i == Items.EMERALD || i == Items.DIAMOND)
{
return 400;
return 100;
}
if (Loader.isModLoaded("ic2"))
{
if (stack == Ic2Items.uraniumDrop)
{
return 400;
return 100;
}
}
return 200;
return 50;
}
private boolean invalidReplicatorItem(ItemStack stack)
@ -448,8 +430,8 @@ public class ReplicatorTileEntity extends TileEntity implements ITickable, ISide
}
NonNullList<ItemStack> copper = OreDictionary.getOres("ingotCopper");
for (ItemStack s : copper)
{
if (s.getDisplayName() == stack.getDisplayName())
{
if (s.getItem().getRegistryName() == stack.getItem().getRegistryName())
{
return false;
}
@ -457,7 +439,7 @@ public class ReplicatorTileEntity extends TileEntity implements ITickable, ISide
NonNullList<ItemStack> tin = OreDictionary.getOres("ingotTin");
for (ItemStack s : tin)
{
if (s.getDisplayName() == stack.getDisplayName())
if (s.getItem().getRegistryName() == stack.getItem().getRegistryName())
{
return false;
}
@ -465,7 +447,7 @@ public class ReplicatorTileEntity extends TileEntity implements ITickable, ISide
NonNullList<ItemStack> silver = OreDictionary.getOres("ingotSilver");
for (ItemStack s : silver)
{
if (s.getDisplayName() == stack.getDisplayName())
if (s.getItem().getRegistryName() == stack.getItem().getRegistryName())
{
return false;
}
@ -473,7 +455,7 @@ public class ReplicatorTileEntity extends TileEntity implements ITickable, ISide
NonNullList<ItemStack> lead = OreDictionary.getOres("ingotLead");
for (ItemStack s : lead)
{
if (s.getDisplayName() == stack.getDisplayName())
if (s.getItem().getRegistryName() == stack.getItem().getRegistryName())
{
return false;
}
@ -481,7 +463,7 @@ public class ReplicatorTileEntity extends TileEntity implements ITickable, ISide
NonNullList<ItemStack> aluminum = OreDictionary.getOres("ingotAluminum");
for (ItemStack s : aluminum)
{
if (s.getDisplayName() == stack.getDisplayName())
if (s.getItem().getRegistryName() == stack.getItem().getRegistryName())
{
return false;
}
@ -489,7 +471,7 @@ public class ReplicatorTileEntity extends TileEntity implements ITickable, ISide
NonNullList<ItemStack> silicon = OreDictionary.getOres("silicon");
for (ItemStack s : silicon)
{
if (s.getDisplayName() == stack.getDisplayName())
if (s.getItem().getRegistryName() == stack.getItem().getRegistryName())
{
return false;
}
@ -541,7 +523,7 @@ public class ReplicatorTileEntity extends TileEntity implements ITickable, ISide
if (canReplicate())
{
ItemStack itemstack = replicatorItemStacks.get(0);
ItemStack itemstack1 = new ItemStack(itemstack.getItem());
ItemStack itemstack1 = itemstack.copy();
ItemStack itemstack2 = replicatorItemStacks.get(2);
if (itemstack2.isEmpty())
@ -557,7 +539,7 @@ public class ReplicatorTileEntity extends TileEntity implements ITickable, ISide
public static int getCreditSpendTime(ItemStack stack) //Could eventually be used for differing denominations of currency.
{
return 10;
return 50;
}
public static boolean isCredit(ItemStack stack)

View File

@ -4,7 +4,6 @@ import com.droog71.prospect.fe.ProspectEnergyStorage;
import ic2.api.energy.prefab.BasicSource;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
@ -16,6 +15,7 @@ public class SolarPanelTileEntity extends TileEntity implements ITickable
{
private Object ic2EnergySource;
private ProspectEnergyStorage energyStorage = new ProspectEnergyStorage();
private int capacity;
private int rating;
private int tier;
@ -26,8 +26,9 @@ public class SolarPanelTileEntity extends TileEntity implements ITickable
public SolarPanelTileEntity(int capacity, int rating, int tier)
{
energyStorage.capacity = capacity;
this.capacity = capacity;
this.rating = rating;
this.tier = tier;
}
@Override
@ -42,6 +43,7 @@ public class SolarPanelTileEntity extends TileEntity implements ITickable
((BasicSource) ic2EnergySource).onLoad(); // notify the energy sink
}
energyStorage.maxReceive = 0;
energyStorage.capacity = capacity;
}
@Override
@ -78,6 +80,9 @@ public class SolarPanelTileEntity extends TileEntity implements ITickable
ic2EnergySource = new BasicSource(this,10,1);
}
((BasicSource) ic2EnergySource).readFromNBT(tag);
capacity = tag.getInteger("capacity");
rating = tag.getInteger("rating");
tier = tag.getInteger("tier");
}
@Override
@ -89,6 +94,9 @@ public class SolarPanelTileEntity extends TileEntity implements ITickable
ic2EnergySource = new BasicSource(this,10,1);
}
((BasicSource) ic2EnergySource).writeToNBT(tag);
tag.setInteger("capacity", capacity);
tag.setInteger("rating", rating);
tag.setInteger("tier", tier);
return tag;
}
@ -98,7 +106,7 @@ public class SolarPanelTileEntity extends TileEntity implements ITickable
if (!world.isRemote) //Everything is done on the server.
{
addEnergy();
giveEnergy();
doWork();
}
}
@ -117,70 +125,21 @@ public class SolarPanelTileEntity extends TileEntity implements ITickable
}
}
private void giveEnergy()
private void doWork()
{
boolean connectedFE = false;
BlockPos[] sides = {pos.add(0,1,0),pos.add(1,0,0),pos.add(0,0,1),pos.add(0,-1,0),pos.add(-1,0,0),pos.add(0,0,-1)};
for (BlockPos p : sides)
if (energyStorage.receivers(world, pos).size() > 0)
{
TileEntity otherTile = world.getTileEntity(p);
if (otherTile != null)
if (Loader.isModLoaded("ic2"))
{
EnumFacing direction = null;
for (EnumFacing facing : EnumFacing.VALUES)
{
IEnergyStorage otherStorage = otherTile.getCapability(CapabilityEnergy.ENERGY,facing);
if (otherStorage != null)
{
if (direction == null)
{
direction = facing;
}
}
}
IEnergyStorage otherStorage = otherTile.getCapability(CapabilityEnergy.ENERGY,direction);
if (otherStorage != null)
{
if (Loader.isModLoaded("ic2"))
{
((BasicSource) ic2EnergySource).setEnergyStored(0);
((BasicSource) ic2EnergySource).setCapacity(0);
connectedFE = true;
}
if (energyStorage.getEnergyStored() >= rating)
{
if (otherStorage.canReceive())
{
if (otherStorage.getEnergyStored() <= otherStorage.getMaxEnergyStored() - rating)
{
otherStorage.receiveEnergy(rating,false);
energyStorage.useEnergy(rating);
}
else
{
otherStorage.receiveEnergy(otherStorage.getMaxEnergyStored() - otherStorage.getEnergyStored(),false);
energyStorage.useEnergy(otherStorage.getMaxEnergyStored() - otherStorage.getEnergyStored());
}
}
}
else if (energyStorage.getEnergyStored() > 0)
{
if (otherStorage.canReceive())
{
if (otherStorage.getEnergyStored() <= otherStorage.getMaxEnergyStored() - energyStorage.getEnergyStored())
{
otherStorage.receiveEnergy(energyStorage.getEnergyStored(),false);
energyStorage.useEnergy(energyStorage.getEnergyStored());
}
else
{
otherStorage.receiveEnergy(otherStorage.getMaxEnergyStored() - otherStorage.getEnergyStored(),false);
energyStorage.useEnergy(otherStorage.getMaxEnergyStored() - otherStorage.getEnergyStored());
}
}
}
}
}
((BasicSource) ic2EnergySource).setEnergyStored(0);
((BasicSource) ic2EnergySource).setCapacity(0);
connectedFE = true;
}
for (IEnergyStorage sink : energyStorage.receivers(world, pos))
{
energyStorage.giveEnergy(energyStorage, sink, rating);
}
}
if (connectedFE == false)
{

View File

@ -1,25 +1,19 @@
package com.droog71.prospect.tilentity;
import com.droog71.prospect.fe.ProspectEnergyStorage;
import com.droog71.prospect.init.ProspectBlocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ITickable;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
public class TransformerTileEntity extends TileEntity implements ITickable
{
private ProspectEnergyStorage energyStorage = new ProspectEnergyStorage();
private int maxReceive;
private int capacity;
private int rating;
private int stepDownRating;
private int stepDownMaxReceive;
@ -31,13 +25,48 @@ public class TransformerTileEntity extends TileEntity implements ITickable
public TransformerTileEntity(int maxReceive, int capacity, int rating)
{
energyStorage.maxReceive = maxReceive;
energyStorage.capacity = capacity;
stepDownMaxReceive = energyStorage.maxReceive;
stepDownRating = rating;
this.maxReceive = maxReceive;
this.capacity = capacity;
this.rating = rating;
}
@Override
public void onLoad()
{
energyStorage.maxReceive = maxReceive;
energyStorage.capacity = capacity;
stepDownMaxReceive = maxReceive;
stepDownRating = rating;
}
@Override
public void invalidate()
{
super.invalidate(); // this is important for mc!
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
maxReceive = tag.getInteger("maxReceive");
capacity = tag.getInteger("capacity");
rating = tag.getInteger("rating");
stepDownMaxReceive = tag.getInteger("stepDownMaxReceive");
stepDownRating = tag.getInteger("stepDownRating");
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tag)
{
tag.setInteger("maxReceive", maxReceive);
tag.setInteger("capacity", capacity);
tag.setInteger("rating", rating);
tag.setInteger("stepDownMaxReceive", stepDownMaxReceive);
tag.setInteger("stepDownRating", stepDownRating);
return tag;
}
@Override
public void update()
{
@ -45,7 +74,7 @@ public class TransformerTileEntity extends TileEntity implements ITickable
{
if (energyStorage.overloaded)
{
explode();
energyStorage.explode(world,pos);
}
else
{
@ -59,71 +88,14 @@ public class TransformerTileEntity extends TileEntity implements ITickable
energyStorage.maxReceive = stepDownMaxReceive;
rating = stepDownRating;
}
giveEnergy();
for (IEnergyStorage sink : energyStorage.receivers(world, pos))
{
energyStorage.giveEnergy(energyStorage, sink, rating);
}
}
}
}
private void giveEnergy()
{
BlockPos[] sides = {pos.add(0,1,0),pos.add(1,0,0),pos.add(0,0,1),pos.add(0,-1,0),pos.add(-1,0,0),pos.add(0,0,-1)};
for (BlockPos p : sides)
{
TileEntity otherTile = world.getTileEntity(p);
if (otherTile != null)
{
EnumFacing direction = null;
for (EnumFacing facing : EnumFacing.VALUES)
{
IEnergyStorage otherStorage = otherTile.getCapability(CapabilityEnergy.ENERGY,facing);
if (otherStorage != null)
{
if (direction == null)
{
direction = facing;
}
}
}
IEnergyStorage otherStorage = otherTile.getCapability(CapabilityEnergy.ENERGY,direction);
if (otherStorage != null)
{
if (energyStorage.getEnergyStored() > 0)
{
if (otherStorage.canReceive())
{
if (otherStorage.getEnergyStored() < otherStorage.getMaxEnergyStored())
{
if (otherStorage.getEnergyStored() < energyStorage.getEnergyStored())
{
int potential = (energyStorage.getEnergyStored() - otherStorage.getEnergyStored())/2;
int output = Math.min(potential, rating);
energyStorage.useEnergy(output);
otherStorage.receiveEnergy(rating, true);
if (otherStorage != null)
{
otherStorage.receiveEnergy(output,false);
}
}
}
}
}
}
}
}
}
private void explode()
{
world.playSound(null, pos, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 0.5f, 1);
WorldServer w = (WorldServer) world;
w.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, pos.getX(), pos.getY(), pos.getZ(), 1, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.LAVA, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
w.spawnParticle(EnumParticleTypes.FLAME, pos.getX(), pos.getY(), pos.getZ(), 10, 0, 0, 0, 1, null);
world.getBlockState(pos).getBlock().breakBlock(world, pos, ProspectBlocks.extruder.getDefaultState());
EntityItem item = new EntityItem(w, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ProspectBlocks.extruder));
w.spawnEntity(item);
world.setBlockToAir(pos);
}
@Override
public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @javax.annotation.Nullable net.minecraft.util.EnumFacing facing)

View File

@ -1,7 +1,7 @@
{
"variants": {
"normal": [
{ "model": "prospect:printer" }
{ "model": "prospect:fabricator" }
]
}
}

View File

@ -31,7 +31,7 @@ item.hv_coil.name=HV Coil
item.ev_coil.name=EV Coil
item.iv_coil.name=IV Coil
item.purifier_schematic.name=Purifier Schematic
item.printer_schematic.name=Printer Schematic
item.fabricator_schematic.name=Fabricator Schematic
item.helmet_schematic.name=Prospector's Helmet Schematic
item.suit_schematic.name=Prospector's Suit Schematic
item.pants_schematic.name=Prospector's Pants Schematic
@ -86,7 +86,7 @@ tile.hv_solar_panel.name=HV Solar Panel
tile.ev_solar_panel.name=EV Solar Panel
tile.iv_solar_panel.name=IV Solar Panel
tile.extruder.name=Extruder
tile.printer.name=Fabricator
tile.fabricator.name=Fabricator
tile.purifier.name=Purifier
tile.living_ore.name=Living Ore
tile.copper_ore.name=Copper Ore

View File

@ -2,7 +2,7 @@
"parent": "block/cube_bottom_top",
"textures": {
"side": "prospect:blocks/plating_dark",
"bottom": "prospect:blocks/plating_dark",
"bottom": "prospect:blocks/ev_cable",
"top": "prospect:blocks/solar_panel"
}
}

View File

@ -1,7 +1,7 @@
{
"parent": "block/cube_bottom_top",
"textures": {
"side": "prospect:blocks/printer_sides",
"side": "prospect:blocks/fabricator_sides",
"bottom": "prospect:blocks/plating_dark",
"top": "prospect:blocks/plating_dark"
}

View File

@ -2,7 +2,7 @@
"parent": "block/cube_bottom_top",
"textures": {
"side": "prospect:blocks/plating_dark",
"bottom": "prospect:blocks/plating_dark",
"bottom": "prospect:blocks/hv_cable",
"top": "prospect:blocks/solar_panel"
}
}

View File

@ -2,7 +2,7 @@
"parent": "block/cube_bottom_top",
"textures": {
"side": "prospect:blocks/plating_dark",
"bottom": "prospect:blocks/plating_dark",
"bottom": "prospect:blocks/iv_cable",
"top": "prospect:blocks/solar_panel"
}
}

View File

@ -2,7 +2,7 @@
"parent": "block/cube_bottom_top",
"textures": {
"side": "prospect:blocks/plating_dark",
"bottom": "prospect:blocks/plating_dark",
"bottom": "prospect:blocks/lv_cable",
"top": "prospect:blocks/solar_panel"
}
}

View File

@ -2,7 +2,7 @@
"parent": "block/cube_bottom_top",
"textures": {
"side": "prospect:blocks/plating_dark",
"bottom": "prospect:blocks/plating_dark",
"bottom": "prospect:blocks/mv_cable",
"top": "prospect:blocks/solar_panel"
}
}

View File

@ -0,0 +1,3 @@
{
"parent": "prospect:block/fabricator"
}

View File

@ -1,7 +1,7 @@
{
"parent": "item/generated",
"textures": {
"layer0": "prospect:items/printer_schematic"
"layer0": "prospect:items/fabricator_schematic"
},
"display": {

View File

@ -1,3 +0,0 @@
{
"parent": "prospect:block/printer"
}

View File

@ -9,7 +9,7 @@
"item": "prospect:hv_transformer"
},
"P": {
"item": "minecraft:hv_solar_panel"
"item": "prospect:hv_solar_panel"
}
},
"result": {

View File

@ -16,7 +16,7 @@
}
},
"result": {
"item": "prospect:printer",
"item": "prospect:fabricator",
"data": 0
}
}

View File

@ -2,7 +2,7 @@
"type": "minecraft:crafting_shapeless",
"ingredients": [
{
"item": "prospect:printer"
"item": "prospect:fabricator"
},
{
"item": "minecraft:paper"
@ -16,6 +16,6 @@
}
],
"result": {
"item": "prospect:printer_schematic"
"item": "prospect:fabricator_schematic"
}
}

View File

@ -9,7 +9,7 @@
"item": "prospect:mv_transformer"
},
"P": {
"item": "minecraft:mv_solar_panel"
"item": "prospect:mv_solar_panel"
}
},
"result": {

View File

@ -9,7 +9,7 @@
"item": "prospect:ev_transformer"
},
"P": {
"item": "minecraft:ev_solar_panel"
"item": "prospect:ev_solar_panel"
}
},
"result": {

View File

@ -9,7 +9,7 @@
"item": "prospect:lv_transformer"
},
"P": {
"item": "minecraft:lv_solar_panel"
"item": "prospect:lv_solar_panel"
}
},
"result": {

View File

@ -1,8 +1,8 @@
{
"printer":
"fabricator":
{
"category": "block",
"sounds": [ "prospect:printer" ]
"sounds": [ "prospect:fabricator" ]
},
"purifier":
{

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB