Added block states and GUI for bio_gen, new GUI textures, fixed tile entity bugs.

master
Droog71 2020-08-07 11:20:02 -04:00
parent bcbc8e1083
commit 01d266a159
26 changed files with 226 additions and 143 deletions

View File

@ -5,9 +5,13 @@ import com.droog71.prospect.Prospect;
import com.droog71.prospect.blocks.ProspectBlockContainer;
import com.droog71.prospect.init.ProspectBlocks;
import com.droog71.prospect.tile_entity.BioGenTileEntity;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
@ -20,12 +24,39 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BioFuelGenerator extends ProspectBlockContainer
{
{
private static boolean keepInventory;
public BioFuelGenerator(String name, Material material)
{
super(name, material);
}
public static void setState(boolean active, World worldIn, BlockPos pos)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
keepInventory = true;
if (active)
{
worldIn.setBlockState(pos, ProspectBlocks.bio_fuel_generator_running.getDefaultState());
worldIn.setBlockState(pos, ProspectBlocks.bio_fuel_generator_running.getDefaultState());
}
else
{
worldIn.setBlockState(pos, ProspectBlocks.bio_fuel_generator.getDefaultState());
worldIn.setBlockState(pos, ProspectBlocks.bio_fuel_generator.getDefaultState());
}
keepInventory = true;
if (tileentity != null)
{
tileentity.validate();
worldIn.setTileEntity(pos, tileentity);
}
}
@Override
public EnumBlockRenderType getRenderType(IBlockState state)
{
@ -79,14 +110,17 @@ public class BioFuelGenerator extends ProspectBlockContainer
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof BioGenTileEntity)
if (!keepInventory)
{
InventoryHelper.dropInventoryItems(worldIn, pos, (BioGenTileEntity)tileentity);
worldIn.updateComparatorOutputLevel(pos, this);
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof BioGenTileEntity)
{
InventoryHelper.dropInventoryItems(worldIn, pos, (BioGenTileEntity)tileentity);
worldIn.updateComparatorOutputLevel(pos, this);
}
}
super.breakBlock(worldIn, pos, state);
super.breakBlock(worldIn, pos, state);
}
@Override

View File

@ -65,15 +65,15 @@ public class BioGenGUI extends GuiContainer
this.drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);
}
int l = this.getBurnProgressScaled(24);
this.drawTexturedModalRect(i + 79, j + 34, 176, 14, l + 1, 16);
int h = this.getBurnProgressScaled(16);
this.drawTexturedModalRect(i + 79, j + 34, 176, 14, 24, h + 1);
}
private int getBurnProgressScaled(int pixels)
{
int i = this.tileBioGen.getField(2);
int j = this.tileBioGen.getField(3);
return j != 0 && i != 0 ? i * pixels / j : 0;
return j != 0 && i != 0 ? i * pixels / j : 16;
}
private int getPowerScaled(int pixels)

View File

@ -1,5 +1,6 @@
package com.droog71.prospect.gui;
import com.droog71.prospect.inventory.BioGenContainer;
import com.droog71.prospect.inventory.ExtruderContainer;
import com.droog71.prospect.inventory.LaunchPadContainer;
import com.droog71.prospect.inventory.PressContainer;
@ -45,7 +46,7 @@ public class ProspectGuiHandler implements IGuiHandler
}
if (ID == 6)
{
return new PressContainer(player.inventory, (BioGenTileEntity)world.getTileEntity(new BlockPos(x,y,z)));
return new BioGenContainer(player.inventory, (BioGenTileEntity)world.getTileEntity(new BlockPos(x,y,z)));
}
return null;
}
@ -75,7 +76,7 @@ public class ProspectGuiHandler implements IGuiHandler
}
if (ID == 6)
{
return new PressGUI(player.inventory, (BioGenTileEntity)world.getTileEntity(new BlockPos(x,y,z)));
return new BioGenGUI(player.inventory, (BioGenTileEntity)world.getTileEntity(new BlockPos(x,y,z)));
}
return null;
}

View File

@ -67,6 +67,7 @@ public class ProspectBlocks
public static Block hv_transformer;
public static Block ev_transformer;
public static Block bio_fuel_generator;
public static Block bio_fuel_generator_running;
public static Block lv_solar_panel;
public static Block mv_solar_panel;
public static Block hv_solar_panel;
@ -114,6 +115,7 @@ public class ProspectBlocks
hv_transformer = new Transformer("hv_transformer",Material.IRON,16000,80000,9000).setHardness(1.0f).setCreativeTab(Prospect.tabProspect);
ev_transformer = new Transformer("ev_transformer",Material.IRON,25000,125000,16000).setHardness(1.0f).setCreativeTab(Prospect.tabProspect);
bio_fuel_generator = new BioFuelGenerator("bio_fuel_generator",Material.IRON).setHardness(1.0f).setCreativeTab(Prospect.tabProspect);
bio_fuel_generator_running = new BioFuelGenerator("bio_fuel_generator_running",Material.IRON).setHardness(1.0f);
lv_solar_panel = new SolarPanel("lv_solar_panel",Material.IRON,64,32,1).setHardness(1.0f).setCreativeTab(Prospect.tabProspect);
mv_solar_panel = new SolarPanel("mv_solar_panel",Material.IRON,256,128,2).setHardness(1.0f).setCreativeTab(Prospect.tabProspect);
hv_solar_panel = new SolarPanel("hv_solar_panel",Material.IRON,1024,512,3).setHardness(1.0f).setCreativeTab(Prospect.tabProspect);
@ -174,6 +176,7 @@ public class ProspectBlocks
event.getRegistry().registerAll(hv_transformer);
event.getRegistry().registerAll(ev_transformer);
event.getRegistry().registerAll(bio_fuel_generator);
event.getRegistry().registerAll(bio_fuel_generator_running);
event.getRegistry().registerAll(lv_solar_panel);
event.getRegistry().registerAll(mv_solar_panel);
event.getRegistry().registerAll(hv_solar_panel);
@ -212,6 +215,7 @@ public class ProspectBlocks
event.getRegistry().registerAll(new ItemBlock(hv_transformer).setRegistryName(hv_transformer.getRegistryName()));
event.getRegistry().registerAll(new ItemBlock(ev_transformer).setRegistryName(ev_transformer.getRegistryName()));
event.getRegistry().registerAll(new ItemBlock(bio_fuel_generator).setRegistryName(bio_fuel_generator.getRegistryName()));
event.getRegistry().registerAll(new ItemBlock(bio_fuel_generator_running).setRegistryName(bio_fuel_generator_running.getRegistryName()));
event.getRegistry().registerAll(new ItemBlock(lv_solar_panel).setRegistryName(lv_solar_panel.getRegistryName()));
event.getRegistry().registerAll(new ItemBlock(mv_solar_panel).setRegistryName(mv_solar_panel.getRegistryName()));
event.getRegistry().registerAll(new ItemBlock(hv_solar_panel).setRegistryName(hv_solar_panel.getRegistryName()));
@ -250,6 +254,7 @@ public class ProspectBlocks
registerRender(Item.getItemFromBlock(hv_transformer));
registerRender(Item.getItemFromBlock(ev_transformer));
registerRender(Item.getItemFromBlock(bio_fuel_generator));
registerRender(Item.getItemFromBlock(bio_fuel_generator_running));
registerRender(Item.getItemFromBlock(lv_solar_panel));
registerRender(Item.getItemFromBlock(mv_solar_panel));
registerRender(Item.getItemFromBlock(hv_solar_panel));

View File

@ -17,6 +17,7 @@ public class ProspectSounds
static ResourceLocation capsuleSoundLocation;
static ResourceLocation extruderSoundLocation;
static ResourceLocation pressSoundLocation;
static ResourceLocation bioFuelGeneratorSoundLocation;
public static SoundEvent fabricatorSoundEvent;
public static SoundEvent purifierSoundEvent;
public static SoundEvent quarrySoundEvent;
@ -25,6 +26,7 @@ public class ProspectSounds
public static SoundEvent capsuleSoundEvent;
public static SoundEvent extruderSoundEvent;
public static SoundEvent pressSoundEvent;
public static SoundEvent bioFuelGeneratorSoundEvent;
public static void init()
{
@ -36,6 +38,7 @@ public class ProspectSounds
capsuleSoundLocation = new ResourceLocation("prospect", "capsule");
extruderSoundLocation = new ResourceLocation("prospect", "extruder");
pressSoundLocation = new ResourceLocation("prospect", "press");
bioFuelGeneratorSoundLocation = new ResourceLocation("prospect", "bio_fuel_generator");
fabricatorSoundEvent = new SoundEvent(fabricatorSoundLocation);
purifierSoundEvent = new SoundEvent(purifierSoundLocation);
quarrySoundEvent = new SoundEvent(quarrySoundLocation);
@ -44,6 +47,8 @@ public class ProspectSounds
capsuleSoundEvent = new SoundEvent(capsuleSoundLocation);
extruderSoundEvent = new SoundEvent(extruderSoundLocation);
pressSoundEvent = new SoundEvent(pressSoundLocation);
bioFuelGeneratorSoundEvent = new SoundEvent(bioFuelGeneratorSoundLocation);
}
public static void registerSoundEvent(String name, SoundEvent event)

View File

@ -1,5 +1,6 @@
package com.droog71.prospect.tile_entity;
import com.droog71.prospect.blocks.energy.BioFuelGenerator;
import com.droog71.prospect.forge_energy.ProspectEnergyStorage;
import com.droog71.prospect.init.ProspectItems;
import com.droog71.prospect.init.ProspectSounds;
@ -19,7 +20,6 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
@ -148,7 +148,6 @@ public class BioGenTileEntity extends TileEntity implements ITickable, ISidedInv
if (index == 0 && !flag)
{
totalburnTime = getburnTime(stack);
burnTime = 0;
markDirty();
}
}
@ -258,36 +257,57 @@ public class BioGenTileEntity extends TileEntity implements ITickable, ISidedInv
*/
@Override
public void update()
{
{
boolean needsNetworkUpdate = false;
boolean clientIsGenerating = burnTime > 0 && burnTime < totalburnTime;
if (!world.isRemote)
{
if (canGenerate())
{
if (burnTime == 0)
{
if (canConsumeFuel())
{
burnTime = 1;
consumeFuel();
needsNetworkUpdate = true;
}
}
if (burnTime > 0 && burnTime < totalburnTime)
{
updateEnergy();
addEnergy();
distributeEnergy();
++burnTime;
if (burnTime == totalburnTime)
{
burnTime = 0;
totalburnTime = getburnTime(bioGenItemStacks.get(0));
burnFuel();
markDirty();
}
effectsTimer++;
burnTime++;
effectsTimer++;
if (effectsTimer > 200)
{
world.playSound(null, pos, ProspectSounds.extruderSoundEvent, SoundCategory.BLOCKS, 0.5f, 1);
world.playSound(null, pos, ProspectSounds.bioFuelGeneratorSoundEvent, SoundCategory.BLOCKS, 0.5f, 1);
effectsTimer = 0;
}
}
else if (burnTime > 0)
{
burnTime = MathHelper.clamp(burnTime - 1, 0, totalburnTime);
}
}
needsNetworkUpdate = true;
}
if (burnTime == totalburnTime)
{
burnTime = 0;
totalburnTime = getburnTime(bioGenItemStacks.get(0));
needsNetworkUpdate = true;
}
if (clientIsGenerating != burnTime > 0 && burnTime < totalburnTime)
{
needsNetworkUpdate = true;
}
BioFuelGenerator.setState(burnTime > 0 && burnTime < totalburnTime, world, pos);
}
if (needsNetworkUpdate)
{
markDirty();
}
}
// Add energy to the buffer
@ -366,9 +386,9 @@ public class BioGenTileEntity extends TileEntity implements ITickable, ISidedInv
}
/**
* Returns true if the genrator can generate power, i.e. has a source item, destination stack isn't full, etc.
* Returns true if the generator can consume fuel, i.e. has a source item, destination stack isn't full, etc.
*/
private boolean canGenerate()
private boolean canConsumeFuel()
{
if (bioGenItemStacks.get(0).isEmpty() || !isFuel(bioGenItemStacks.get(0)))
{
@ -409,25 +429,22 @@ public class BioGenTileEntity extends TileEntity implements ITickable, ISidedInv
/**
* Turn one item from the generator source stack into the appropriate resulting item in the generator result stack
*/
public void burnFuel()
public void consumeFuel()
{
if (canGenerate())
ItemStack itemstack = bioGenItemStacks.get(0);
ItemStack itemstack1 = new ItemStack(Items.BUCKET);
ItemStack itemstack2 = bioGenItemStacks.get(2);
if (itemstack2.isEmpty())
{
ItemStack itemstack = bioGenItemStacks.get(0);
ItemStack itemstack1 = new ItemStack(Items.BUCKET);
ItemStack itemstack2 = bioGenItemStacks.get(2);
if (itemstack2.isEmpty())
{
bioGenItemStacks.set(2, itemstack1.copy());
}
else if (itemstack2.getItem() == itemstack1.getItem())
{
itemstack2.grow(itemstack1.getCount());
}
itemstack.shrink(1);
bioGenItemStacks.set(2, itemstack1.copy());
}
else if (itemstack2.getItem() == itemstack1.getItem())
{
itemstack2.grow(itemstack1.getCount());
}
itemstack.shrink(1);
}
/**

View File

@ -258,7 +258,9 @@ public class ExtruderTileEntity extends TileEntity implements ITickable, ISidedI
*/
@Override
public void update()
{
{
boolean needsNetworkUpdate = false;
if (!world.isRemote)
{
if (energyStorage.overloaded)
@ -270,33 +272,33 @@ public class ExtruderTileEntity extends TileEntity implements ITickable, ISidedI
updateEnergy();
if (canExtrude() && useEnergy())
{
doWork();
++extrudeTime;
if (extrudeTime == totalextrudeTime)
{
extrudeTime = 0;
totalextrudeTime = getextrudeTime(extruderItemStacks.get(0));
extrudeItem();
needsNetworkUpdate = true;
}
effectsTimer++;
if (effectsTimer > 200)
{
world.playSound(null, pos, ProspectSounds.extruderSoundEvent, SoundCategory.BLOCKS, 0.5f, 1);
effectsTimer = 0;
}
}
else if (extrudeTime > 0)
{
extrudeTime = MathHelper.clamp(extrudeTime - 1, 0, totalextrudeTime);
}
}
}
}
private void doWork()
{
++extrudeTime;
if (extrudeTime == totalextrudeTime)
}
if (needsNetworkUpdate)
{
extrudeTime = 0;
totalextrudeTime = getextrudeTime(extruderItemStacks.get(0));
extrudeItem();
markDirty();
}
effectsTimer++;
if (effectsTimer > 200)
{
world.playSound(null, pos, ProspectSounds.extruderSoundEvent, SoundCategory.BLOCKS, 0.5f, 1);
effectsTimer = 0;
}
}
// Get values from the energy storage or ic2 energy sink

View File

@ -272,7 +272,9 @@ public class FabricatorTileEntity extends TileEntity implements ITickable, ISide
*/
@Override
public void update()
{
{
boolean needsNetworkUpdate = false;
if (!world.isRemote)
{
if (energyStorage.overloaded)
@ -284,7 +286,22 @@ public class FabricatorTileEntity extends TileEntity implements ITickable, ISide
updateEnergy();
if (itemsConsumed && useEnergy())
{
doWork();
++fabricateTime;
if (fabricateTime == totalfabricateTime)
{
fabricateTime = 0;
totalfabricateTime = getfabricateTime(fabricatorItemStacks.get(0));
fabricateItem();
needsNetworkUpdate = true;
}
effectsTimer++;
if (effectsTimer > 40)
{
world.playSound(null, pos, ProspectSounds.fabricatorSoundEvent, SoundCategory.BLOCKS, 0.25f, 1);
effectsTimer = 0;
}
}
else if (canFabricate() && useEnergy())
{
@ -296,27 +313,17 @@ public class FabricatorTileEntity extends TileEntity implements ITickable, ISide
}
}
}
if (needsNetworkUpdate)
{
markDirty();
}
}
// Fabricate items and plays the sound effect
private void doWork()
{
++fabricateTime;
if (fabricateTime == totalfabricateTime)
{
fabricateTime = 0;
totalfabricateTime = getfabricateTime(fabricatorItemStacks.get(0));
fabricateItem();
markDirty();
}
effectsTimer++;
if (effectsTimer > 40)
{
world.playSound(null, pos, ProspectSounds.fabricatorSoundEvent, SoundCategory.BLOCKS, 0.25f, 1);
effectsTimer = 0;
}
}
// Get values from the energy storage or ic2 energy sink

View File

@ -267,7 +267,9 @@ public class LaunchPadTileEntity extends TileEntity implements ITickable, ISided
*/
@Override
public void update()
{
{
boolean needsNetworkUpdate = false;
if (!world.isRemote)
{
if (energyStorage.overloaded)
@ -277,24 +279,21 @@ public class LaunchPadTileEntity extends TileEntity implements ITickable, ISided
else
{
updateEnergy();
if (isEnergized())
{
if (canLaunch())
if (canLaunch() && useEnergy())
{
++launchTime;
if (launchTime == totalLaunchTime)
{
if (useEnergy())
{
doWork();
}
launchTime = 0;
totalLaunchTime = getlaunchTime(launchPadItemStacks.get(0));
launchItem();
needsNetworkUpdate = true;
}
else
{
launchTime = 0;
}
}
}
else if (launchTime > 0)
{
launchTime = MathHelper.clamp(launchTime - 2, 0, totalLaunchTime);
}
}
}
if (capsuleYpos > 0 && capsuleYpos < 500)
{
@ -305,7 +304,12 @@ public class LaunchPadTileEntity extends TileEntity implements ITickable, ISided
world.setBlockToAir(new BlockPos(pos.getX(),pos.getY()+capsuleYpos-1,pos.getZ()));
capsuleYpos = 0;
}
}
}
if (needsNetworkUpdate)
{
markDirty();
}
}
// Spawns particle effects, plays sound and moves capsule 1 block above the launch pad
@ -329,20 +333,7 @@ public class LaunchPadTileEntity extends TileEntity implements ITickable, ISided
world.setBlockState(new BlockPos(pos.getX(),pos.getY()+capsuleYpos,pos.getZ()), ProspectBlocks.capsule.getDefaultState());
capsuleYpos++;
}
// Increases the progress each tick and launches the capsule at the end
private void doWork()
{
++launchTime;
if (launchTime == totalLaunchTime)
{
launchTime = 0;
totalLaunchTime = getlaunchTime(launchPadItemStacks.get(0));
launchItem();
markDirty();
}
}
// Get values from the energy storage or ic2 energy sink
private void updateEnergy()
{

View File

@ -257,7 +257,9 @@ public class PressTileEntity extends TileEntity implements ITickable, ISidedInve
*/
@Override
public void update()
{
{
boolean needsNetworkUpdate = false;
if (!world.isRemote)
{
if (energyStorage.overloaded)
@ -269,35 +271,35 @@ public class PressTileEntity extends TileEntity implements ITickable, ISidedInve
updateEnergy();
if (canPress() && useEnergy())
{
doWork();
++pressTime;
if (pressTime == totalpressTime)
{
pressTime = 0;
totalpressTime = getpressTime(pressItemStacks.get(0));
pressItem();
needsNetworkUpdate = true;
}
effectsTimer++;
if (effectsTimer > 55)
{
world.playSound(null, pos, ProspectSounds.pressSoundEvent, SoundCategory.BLOCKS, 1.0f, 1);
effectsTimer = 0;
}
}
else if (pressTime > 0)
{
pressTime = MathHelper.clamp(pressTime - 1, 0, totalpressTime);
}
}
}
}
private void doWork()
{
++pressTime;
if (pressTime == totalpressTime)
}
if (needsNetworkUpdate)
{
pressTime = 0;
totalpressTime = getpressTime(pressItemStacks.get(0));
pressItem();
markDirty();
}
effectsTimer++;
if (effectsTimer > 55)
{
world.playSound(null, pos, ProspectSounds.pressSoundEvent, SoundCategory.BLOCKS, 1.0f, 1);
effectsTimer = 0;
}
}
// Get values from the energy storage or ic2 energy sink
private void updateEnergy()
{

View File

@ -324,11 +324,6 @@ public class ReplicatorTileEntity extends TileEntity implements ITickable, ISide
{
replicateTime = MathHelper.clamp(replicateTime - 1, 0, totalreplicateTime);
}
if (needsNetworkUpdate)
{
markDirty();
}
}
}

View File

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

View File

@ -82,6 +82,7 @@ item.pants.name=Prospector's Pants
item.boots.name=Prospector's Boots
tile.quarry.name=Industrial Quarry
tile.bio_fuel_generator.name=Bio Fuel Generator
tile.bio_fuel_generator_running.name=Bio Fuel Generator
tile.lv_solar_panel.name=LV Solar Panel
tile.mv_solar_panel.name=MV Solar Panel
tile.hv_solar_panel.name=HV Solar Panel

View File

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

View File

@ -0,0 +1,8 @@
{
"parent": "block/cube_bottom_top",
"textures": {
"side": "prospect:blocks/bio_fuel_generator_running",
"bottom": "prospect:blocks/plating_dark",
"top": "prospect:blocks/plating_dark"
}
}

View File

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

View File

@ -38,5 +38,10 @@
{
"category": "block",
"sounds": [ "prospect:press" ]
},
"bio_fuel_generator":
{
"category": "block",
"sounds": [ "prospect:bio_fuel_generator" ]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1023 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB