Lot of formatting.

This commit is contained in:
drcrazy 2018-06-22 18:22:16 +03:00
parent ec13f82628
commit 1de3fe5dc5
29 changed files with 540 additions and 544 deletions

View file

@ -365,10 +365,9 @@ public class TileAutoCraftingTable extends TilePowerAcceptor
if (canMake(recipe)) {
if (canUseEnergy(euTick)) {
progress++;
if(progress == 1){
world.playSound(null, pos.getX(), pos.getY(),
pos.getZ(), ModSounds.AUTO_CRAFTING,
SoundCategory.BLOCKS, 0.3F, 0.8F);
if (progress == 1) {
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.AUTO_CRAFTING,
SoundCategory.BLOCKS, 0.3F, 0.8F);
}
useEnergy(euTick);
}

View file

@ -63,47 +63,50 @@ public class TileElectricFurnace extends TilePowerAcceptor
super();
}
public int gaugeProgressScaled(final int scale) {
return this.progress * scale / this.fuelScale;
public int gaugeProgressScaled(int scale) {
return progress * scale / fuelScale;
}
public void cookItems() {
if (this.canSmelt()) {
final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.getStackInSlot(this.input1));
if (canSmelt()) {
final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1));
if (this.getStackInSlot(this.output) == ItemStack.EMPTY) {
this.setInventorySlotContents(this.output, itemstack.copy());
} else if (this.getStackInSlot(this.output).isItemEqual(itemstack)) {
this.getStackInSlot(this.output).grow(itemstack.getCount());
if (getStackInSlot(output) == ItemStack.EMPTY) {
setInventorySlotContents(output, itemstack.copy());
} else if (getStackInSlot(output).isItemEqual(itemstack)) {
getStackInSlot(output).grow(itemstack.getCount());
}
if (this.getStackInSlot(this.input1).getCount() > 1) {
this.decrStackSize(this.input1, 1);
if (getStackInSlot(input1).getCount() > 1) {
decrStackSize(input1, 1);
} else {
this.setInventorySlotContents(this.input1, ItemStack.EMPTY);
setInventorySlotContents(input1, ItemStack.EMPTY);
}
}
}
public boolean canSmelt() {
if (this.getStackInSlot(this.input1) == ItemStack.EMPTY) {
if (getStackInSlot(input1) == ItemStack.EMPTY) {
return false;
}
final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.getStackInSlot(this.input1));
if (itemstack.isEmpty())
final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1));
if (itemstack.isEmpty()) {
return false;
if (this.getStackInSlot(this.output) == ItemStack.EMPTY)
}
if (getStackInSlot(output) == ItemStack.EMPTY) {
return true;
if (!this.getStackInSlot(this.output).isItemEqual(itemstack))
}
if (!getStackInSlot(output).isItemEqual(itemstack)) {
return false;
final int result = this.getStackInSlot(this.output).getCount() + itemstack.getCount();
}
final int result = getStackInSlot(output).getCount() + itemstack.getCount();
return result <= this.getInventoryStackLimit() && result <= itemstack.getMaxStackSize();
}
public boolean isBurning() {
return this.getEnergy() > getEuPerTick(this.cost);
return getEnergy() > getEuPerTick(cost);
}
public ItemStack getResultFor(final ItemStack stack) {
public ItemStack getResultFor(ItemStack stack) {
final ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack);
if (!result.isEmpty()) {
return result.copy();
@ -112,26 +115,26 @@ public class TileElectricFurnace extends TilePowerAcceptor
}
public void updateState() {
if (wasBurning != (this.progress > 0)) {
if (wasBurning != (progress > 0)) {
// skips updating the block state for 1 tick, to prevent the machine from
// turning on/off rapidly causing fps drops
if (wasBurning && this.progress == 0 && canSmelt()) {
if (wasBurning && progress == 0 && canSmelt()) {
wasBurning = true;
return;
}
final IBlockState BlockStateContainer = this.world.getBlockState(this.pos);
final IBlockState BlockStateContainer = world.getBlockState(pos);
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != this.progress > 0)
blockMachineBase.setActive(this.progress > 0, this.world, this.pos);
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != progress > 0)
blockMachineBase.setActive(progress > 0, world, pos);
}
wasBurning = (this.progress > 0);
wasBurning = (progress > 0);
}
}
public int getBurnTime() {
return this.progress;
return progress;
}
public void setBurnTime(final int burnTime) {
@ -146,32 +149,31 @@ public class TileElectricFurnace extends TilePowerAcceptor
}
super.update();
this.charge(2);
charge(2);
final boolean burning = this.isBurning();
final boolean burning = isBurning();
boolean updateInventory = false;
if (this.isBurning() && this.canSmelt()) {
this.updateState();
if (canUseEnergy(getEuPerTick(this.cost))) {
this.useEnergy(getEuPerTick(this.cost));
this.progress++;
if (this.progress >= Math.max((int) (fuelScale * (1.0 - getSpeedMultiplier())), 5)) {
this.progress = 0;
this.cookItems();
if (isBurning() && canSmelt()) {
updateState();
if (canUseEnergy(getEuPerTick(cost))) {
useEnergy(getEuPerTick(cost));
progress++;
if (progress >= Math.max((int) (fuelScale * (1.0 - getSpeedMultiplier())), 5)) {
progress = 0;
cookItems();
updateInventory = true;
}
}
} else {
this.progress = 0;
this.updateState();
progress = 0;
updateState();
}
if (burning != this.isBurning()) {
if (burning != isBurning()) {
updateInventory = true;
}
if (updateInventory) {
this.markDirty();
markDirty();
}
}
@Override
@ -208,7 +210,7 @@ public class TileElectricFurnace extends TilePowerAcceptor
// IInventoryProvider
@Override
public Inventory getInventory() {
return this.inventory;
return inventory;
}
// IContainerProvider

View file

@ -91,8 +91,8 @@ public class TilePlayerDectector extends TilePowerAcceptor implements IToolDrop
useEnergy(euPerTick);
}
if (lastRedstone != redstone) {
WorldUtils.updateBlock(world, getPos());
world.notifyNeighborsOfStateChange(getPos(), world.getBlockState(getPos()).getBlock(), true);
WorldUtils.updateBlock(world, pos);
world.notifyNeighborsOfStateChange(pos, world.getBlockState(pos).getBlock(), true);
}
}
}

View file

@ -62,59 +62,62 @@ public class TileRecycler extends TilePowerAcceptor
super();
}
public int gaugeProgressScaled(final int scale) {
return this.progress * scale / this.time;
public int gaugeProgressScaled(int scale) {
return progress * scale / time;
}
public int getProgress() {
return this.progress;
return progress;
}
public void setProgress(final int progress) {
public void setProgress(int progress) {
this.progress = progress;
}
public void recycleItems() {
final ItemStack itemstack = ItemParts.getPartByName("scrap");
final int randomchance = this.world.rand.nextInt(this.chance);
final int randomchance = this.world.rand.nextInt(chance);
if (randomchance == 1) {
if (this.getStackInSlot(1).isEmpty())
this.setInventorySlotContents(1, itemstack.copy());
else
if (getStackInSlot(1).isEmpty()) {
setInventorySlotContents(1, itemstack.copy());
}
else {
this.getStackInSlot(1).grow(itemstack.getCount());
}
}
this.decrStackSize(0, 1);
decrStackSize(0, 1);
}
public boolean canRecycle() {
return this.getStackInSlot(0) != ItemStack.EMPTY && this.hasSlotGotSpace(1);
return getStackInSlot(0) != ItemStack.EMPTY && hasSlotGotSpace(1);
}
public boolean hasSlotGotSpace(final int slot) {
if (this.getStackInSlot(slot) == ItemStack.EMPTY) {
public boolean hasSlotGotSpace(int slot) {
if (getStackInSlot(slot) == ItemStack.EMPTY) {
return true;
} else if (this.getStackInSlot(slot).getCount() < this.getStackInSlot(slot).getMaxStackSize()) {
} else if (getStackInSlot(slot).getCount() < getStackInSlot(slot).getMaxStackSize()) {
return true;
}
return false;
}
public boolean isBurning() {
return this.isBurning;
return isBurning;
}
public void setBurning(final boolean burning) {
public void setBurning(boolean burning) {
this.isBurning = burning;
}
public void updateState() {
final IBlockState BlockStateContainer = this.world.getBlockState(this.pos);
final IBlockState BlockStateContainer = world.getBlockState(pos);
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
boolean shouldBurn = this.isBurning || (this.canRecycle() && this.canUseEnergy(getEuPerTick(this.cost)));
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != shouldBurn)
blockMachineBase.setActive(this.isBurning, this.world, this.pos);
boolean shouldBurn = isBurning || (canRecycle() && canUseEnergy(getEuPerTick(cost)));
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != shouldBurn) {
blockMachineBase.setActive(isBurning, world, pos);
}
}
}
@ -122,29 +125,32 @@ public class TileRecycler extends TilePowerAcceptor
@Override
public void update() {
super.update();
if (this.world.isRemote)
if (world.isRemote) {
return;
}
charge(2);
boolean updateInventory = false;
if (this.canRecycle() && !this.isBurning() && this.getEnergy() != 0)
this.setBurning(true);
else if (this.isBurning()) {
if (this.useEnergy(getEuPerTick(this.cost)) != getEuPerTick(this.cost))
if (canRecycle() && !isBurning() && getEnergy() != 0) {
setBurning(true);
}
else if (isBurning()) {
if (useEnergy(getEuPerTick(cost)) != getEuPerTick(cost)) {
this.setBurning(false);
this.progress++;
if (this.progress >= Math.max((int) (this.time* (1.0 - getSpeedMultiplier())), 1)) {
this.progress = 0;
this.recycleItems();
}
progress++;
if (progress >= Math.max((int) (time* (1.0 - getSpeedMultiplier())), 1)) {
progress = 0;
recycleItems();
updateInventory = true;
this.setBurning(false);
setBurning(false);
}
}
this.updateState();
this.charge(2);
updateState();
if (updateInventory) {
this.markDirty();
markDirty();
}
}
@ -154,12 +160,12 @@ public class TileRecycler extends TilePowerAcceptor
}
@Override
public boolean canAcceptEnergy(final EnumFacing direction) {
public boolean canAcceptEnergy(EnumFacing direction) {
return true;
}
@Override
public boolean canProvideEnergy(final EnumFacing direction) {
public boolean canProvideEnergy(EnumFacing direction) {
return false;
}
@ -181,7 +187,7 @@ public class TileRecycler extends TilePowerAcceptor
// IToolDrop
@Override
public ItemStack getToolDrop(final EntityPlayer entityPlayer) {
public ItemStack getToolDrop(EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.RECYCLER, 1);
}
@ -193,7 +199,7 @@ public class TileRecycler extends TilePowerAcceptor
// IContainerProvider
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
public BuiltContainer createContainer(EntityPlayer player) {
return new ContainerBuilder("recycler").player(player.inventory).inventory().hotbar().addInventory()
.tile(this).slot(0, 55, 45).outputSlot(1, 101, 45).energySlot(2, 8, 72).syncEnergyValue()
.syncIntegerValue(this::getProgress, this::setProgress).addInventory().create(this);

View file

@ -112,64 +112,69 @@ public class TileRollingMachine extends TilePowerAcceptor
@Override
public void update() {
super.update();
this.charge(2);
if (!this.world.isRemote) {
InventoryCrafting craftMatrix = getCraftingMatrix();
this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, this.world);
if (this.currentRecipe != null) {
if (world.getTotalWorldTime() % 2 == 0) {
Optional<InventoryCrafting> balanceResult = balanceRecipe(craftMatrix);
if (balanceResult.isPresent()) {
craftMatrix = balanceResult.get();
}
}
this.currentRecipeOutput = currentRecipe.getCraftingResult(craftMatrix);
} else {
this.currentRecipeOutput = ItemStack.EMPTY;
}
if (world.isRemote) {
return;
}
charge(2);
if (!this.currentRecipeOutput.isEmpty() && this.canMake(craftMatrix)) {
if (this.tickTime >= Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1)) {
this.currentRecipeOutput = RollingMachineRecipe.instance.findMatchingRecipeOutput(craftMatrix, this.world);
if (!this.currentRecipeOutput.isEmpty()) {
boolean hasCrafted = false;
if (this.inventory.getStackInSlot(outputSlot) == ItemStack.EMPTY) {
this.inventory.setInventorySlotContents(outputSlot, this.currentRecipeOutput);
this.tickTime = 0;
InventoryCrafting craftMatrix = getCraftingMatrix();
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world);
if (currentRecipe != null) {
if (world.getTotalWorldTime() % 2 == 0) {
Optional<InventoryCrafting> balanceResult = balanceRecipe(craftMatrix);
if (balanceResult.isPresent()) {
craftMatrix = balanceResult.get();
}
}
currentRecipeOutput = currentRecipe.getCraftingResult(craftMatrix);
} else {
currentRecipeOutput = ItemStack.EMPTY;
}
if (!currentRecipeOutput.isEmpty() && canMake(craftMatrix)) {
if (tickTime >= Math.max((int) (runTime * (1.0 - getSpeedMultiplier())), 1)) {
currentRecipeOutput = RollingMachineRecipe.instance.findMatchingRecipeOutput(craftMatrix, world);
if (!currentRecipeOutput.isEmpty()) {
boolean hasCrafted = false;
if (inventory.getStackInSlot(outputSlot) == ItemStack.EMPTY) {
inventory.setInventorySlotContents(outputSlot, currentRecipeOutput);
tickTime = 0;
hasCrafted = true;
} else {
if (inventory.getStackInSlot(outputSlot).getCount()
+ currentRecipeOutput.getCount() <= currentRecipeOutput.getMaxStackSize()) {
final ItemStack stack = inventory.getStackInSlot(outputSlot);
stack.setCount(stack.getCount() + currentRecipeOutput.getCount());
inventory.setInventorySlotContents(outputSlot, stack);
tickTime = 0;
hasCrafted = true;
} else {
if (this.inventory.getStackInSlot(outputSlot).getCount() + this.currentRecipeOutput.getCount() <= this.currentRecipeOutput
.getMaxStackSize()) {
final ItemStack stack = this.inventory.getStackInSlot(outputSlot);
stack.setCount(stack.getCount() + this.currentRecipeOutput.getCount());
this.inventory.setInventorySlotContents(outputSlot, stack);
this.tickTime = 0;
hasCrafted = true;
}
}
if (hasCrafted) {
for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
inventory.decrStackSize(i, 1);
}
this.currentRecipeOutput = ItemStack.EMPTY;
this.currentRecipe = null;
}
}
}
} else {
this.tickTime = 0;
}
if (!this.currentRecipeOutput.isEmpty()) {
if (this.canUseEnergy(getEuPerTick(energyPerTick)) && this.tickTime < Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1) && canMake(craftMatrix)) {
this.useEnergy(getEuPerTick(energyPerTick));
this.tickTime++;
if (hasCrafted) {
for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
inventory.decrStackSize(i, 1);
}
currentRecipeOutput = ItemStack.EMPTY;
currentRecipe = null;
}
}
}
if (this.currentRecipeOutput.isEmpty()) {
this.tickTime = 0;
this.currentRecipe = null;
} else {
tickTime = 0;
}
if (!currentRecipeOutput.isEmpty()) {
if (canUseEnergy(getEuPerTick(energyPerTick))
&& tickTime < Math.max((int) (runTime * (1.0 - getSpeedMultiplier())), 1)
&& canMake(craftMatrix)) {
useEnergy(getEuPerTick(energyPerTick));
tickTime++;
}
}
if (currentRecipeOutput.isEmpty()) {
tickTime = 0;
currentRecipe = null;
}
}
public Optional<InventoryCrafting> balanceRecipe(InventoryCrafting craftCache) {
@ -301,11 +306,11 @@ public class TileRollingMachine extends TilePowerAcceptor
@Override
public Inventory getInventory() {
return this.inventory;
return inventory;
}
public int getBurnTime() {
return this.tickTime;
return tickTime;
}
public void setBurnTime(final int burnTime) {
@ -313,10 +318,10 @@ public class TileRollingMachine extends TilePowerAcceptor
}
public int getBurnTimeRemainingScaled(final int scale) {
if (this.tickTime == 0 || Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1) == 0) {
if (tickTime == 0 || Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1) == 0) {
return 0;
}
return this.tickTime * scale / Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1);
return tickTime * scale / Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1);
}
@Override