Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed miningLaser stucking on clusters & rtg and arc furnaces interactions with hoppers #133

Open
wants to merge 3 commits into
base: Custom-1.12.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/main/java/com/hbm/tileentity/TileEntityMachineBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ public void setCustomName(String name) {
}

public boolean isUseableByPlayer(EntityPlayer player) {
if(world.getTileEntity(pos) != this)
{
return checkUsableByPlayer(player, 128);
}

protected boolean checkUsableByPlayer(EntityPlayer player, double distance) {
if (world.getTileEntity(pos) != this) {
return false;
}else{
return player.getDistanceSq(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D) <=128;
} else {
return player.getDistanceSq(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D) <= distance;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,46 @@
import com.hbm.packet.AuxElectricityPacket;
import com.hbm.packet.AuxGaugePacket;
import com.hbm.packet.PacketDispatcher;
import com.hbm.tileentity.TileEntityMachineBase;

import api.hbm.energy.IBatteryItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;

public class TileEntityMachineArcFurnace extends TileEntity implements ITickable, IConsumer {

public ItemStackHandler inventory;
public class TileEntityMachineArcFurnace extends TileEntityMachineBase implements ITickable, IConsumer {

public int dualCookTime;
public long power;
public static final long maxPower = 50000;
public static final int processingSpeed = 20;

//0: i
//1: o
//2: 1
//3: 2
//4: 3
//5: b
//private static final int[] slots_top = new int[] {0, 2, 3, 4, 5};
//private static final int[] slots_bottom = new int[] {1, 2, 3, 4, 5};
//private static final int[] slots_side = new int[] {0};

private String customName;

public TileEntityMachineArcFurnace() {
inventory = new ItemStackHandler(6){
@Override
protected void onContentsChanged(int slot) {
markDirty();
super.onContentsChanged(slot);
}

@Override
public boolean isItemValid(int slot, ItemStack stack) {
if(slot == 2 || slot == 3 || slot == 4)
return stack.getItem() == ModItems.arc_electrode || stack.getItem() == ModItems.arc_electrode_desh;
return super.isItemValid(slot, stack);
}
};
}

public String getInventoryName() {
return this.hasCustomInventoryName() ? this.customName : "container.arcFurnace";
}
//0: input
//1: output
//2: 1 electrod
//3: 2 electrod
//4: 3 electrod
// 5: battery
private static final int[] slots_top = new int[] { 0 };
private static final int[] slots_bottom = new int[] { 1 };
private static final int[] slots_side = new int[] { 2, 3, 4, 5 };

public boolean hasCustomInventoryName() {
return this.customName != null && this.customName.length() > 0;
public TileEntityMachineArcFurnace() {
super(6);
}

public void setCustomName(String name) {
this.customName = name;
@Override
public String getName() {
return "container.arcFurnace";
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
if(world.getTileEntity(pos) != this)
{
return false;
}else{
return player.getDistanceSq(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D) <=64;
}
return checkUsableByPlayer(player, 64);
}

@Override
Expand All @@ -95,6 +65,51 @@ public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setTag("inventory", inventory.serializeNBT());
return super.writeToNBT(compound);
}

@Override
public int[] getAccessibleSlotsFromSide(EnumFacing e) {
int i = e.ordinal();
return i == 0 ? slots_bottom : (i == 1 ? slots_top : slots_side);
}

@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
if (slot == 1) {
return false;
}

if (slot == 2 || slot == 3 || slot == 4) {
return stack.getItem() == ModItems.arc_electrode || stack.getItem() == ModItems.arc_electrode_desh;
}

if (slot == 5 && stack.getItem() instanceof IBatteryItem) {
return true;
}

if (slot == 0) {
return true;
}

return false;
}

@Override
public boolean canInsertItem(int slot, ItemStack itemStack, int amount) {
return isItemValidForSlot(slot, itemStack);
}

@Override
public boolean canExtractItem(int slot, ItemStack itemStack, int amount) {
if(slot == 1)
return true;

if(slot == 5)
if (itemStack.getItem() instanceof IBatteryItem && ((IBatteryItem)itemStack.getItem()).getCharge(itemStack) == 0)
return true;

return false;
}


public int getDiFurnaceProgressScaled(int i) {
return (dualCookTime * i) / processingSpeed;
Expand Down Expand Up @@ -262,19 +277,4 @@ public long getPower() {
public long getMaxPower() {
return maxPower;
}

@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
}

@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(inventory);
} else {
return super.getCapability(capability, facing);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,9 @@ public String getName() {
return "container.electricFurnace";
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
if(world.getTileEntity(pos) != this)
{
return false;
}else{
return player.getDistanceSq(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D) <=64;
}
return checkUsableByPlayer(player, 64);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ public DrillType getDrillTier(){

@Override
public int getDrillRating(){
return 100;
return 65;
}

}
94 changes: 53 additions & 41 deletions src/main/java/com/hbm/tileentity/machine/TileEntityRtgFurnace.java
Original file line number Diff line number Diff line change
@@ -1,62 +1,40 @@
package com.hbm.tileentity.machine;

import com.hbm.blocks.machine.MachineRtgFurnace;
import com.hbm.items.ModItems;
import com.hbm.tileentity.TileEntityMachineBase;

import com.hbm.util.RTGUtil;
import com.hbm.items.machine.ItemRTGPellet;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;

public class TileEntityRtgFurnace extends TileEntity implements ITickable {

public ItemStackHandler inventory;
public class TileEntityRtgFurnace extends TileEntityMachineBase implements ITickable {

public int dualCookTime;
public int heat;
public static final int processingSpeed = 3000;

// private static final int[] slots_top = new int[] {0};
// private static final int[] slots_bottom = new int[] {4};
// private static final int[] slots_side = new int[] {1, 2, 3};

private String customName;
private static final int[] slots_top = new int[] {0};
private static final int[] slots_bottom = new int[] {4};
private static final int[] slots_side = new int[] {1, 2, 3};

public TileEntityRtgFurnace() {
inventory = new ItemStackHandler(5) {
@Override
protected void onContentsChanged(int slot) {
markDirty();
super.onContentsChanged(slot);
}
};
}

public String getInventoryName() {
return this.hasCustomInventoryName() ? this.customName : "container.rtgFurnace";
}

public boolean hasCustomInventoryName() {
return this.customName != null && this.customName.length() > 0;
super(5);
}

public void setCustomName(String name) {
this.customName = name;
@Override
public String getName() {
return "container.rtgFurnace";
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
if(world.getTileEntity(pos) != this) {
return false;
} else {
return player.getDistanceSq(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D) <= 64;
}
return checkUsableByPlayer(player, 64);
}

public boolean isLoaded() {
Expand All @@ -65,7 +43,7 @@ public boolean isLoaded() {

@Override
public void readFromNBT(NBTTagCompound compound) {
dualCookTime = compound.getShort("CookTime");
dualCookTime = compound.getShort("cookTime");
if(compound.hasKey("inventory"))
inventory.deserializeNBT(compound.getCompoundTag("inventory"));
super.readFromNBT(compound);
Expand Down Expand Up @@ -185,13 +163,47 @@ public void update() {
}

@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
public int[] getAccessibleSlotsFromSide(EnumFacing e) {
int slot = e.ordinal();
return slot == 0 ? slots_bottom : (slot == 1 ? slots_top : slots_side);
}


@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
if(slot == 1 || slot == 2 || slot == 3){
return stack.getItem() instanceof ItemRTGPellet;
}

if(slot == 4)
return false;

return true;
}

@Override
public boolean canInsertItem(int slot, ItemStack stack, int amount) {
return isItemValidForSlot(slot, stack);
}

@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ? CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(inventory) : super.getCapability(capability, facing);
public boolean canExtractItem(int slot, ItemStack stack, int amount) {
if (slot == 4)
return true;

if (slot == 1 || slot == 2 || slot == 3) {
if(stack == ItemStack.EMPTY){
return false;
}

if(stack.getItem() instanceof ItemRTGPellet){
ItemRTGPellet pellet = (ItemRTGPellet) stack.getItem();
if (RTGUtil.getPower(pellet, stack) == 0) {
return true;
}
}
}

return false;
}

}