mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 16:58:34 +01:00
Did lots of Comment stuff on the ESD to make it more understandable
This commit is contained in:
parent
55f4f07065
commit
2dbaaf24dd
5 changed files with 77 additions and 8 deletions
|
@ -28,9 +28,11 @@ public class MultiBlockHelper{
|
||||||
|
|
||||||
//Setting Min and Max Boundaries of the MultiBlock
|
//Setting Min and Max Boundaries of the MultiBlock
|
||||||
|
|
||||||
//Horizontal X+
|
//Horizontal X+ +1/-1 to prevent bigger MultiBlocks from working too
|
||||||
for(int i = blockX; i < blockX+block.getSizeHor(); i++){
|
for(int i = blockX; i < blockX+block.getSizeHor()+1; i++){
|
||||||
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(i, blockY, blockZ))){
|
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(i, blockY, blockZ))){
|
||||||
|
//TODO To Fix the two MultiBlocks next to each other issue, try to take away the -1, check for more Blocks
|
||||||
|
//TODO That could fail the thing and then, later, remove one Block and check if the size is correct still
|
||||||
maxX = i-1;
|
maxX = i-1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +40,7 @@ public class MultiBlockHelper{
|
||||||
}
|
}
|
||||||
|
|
||||||
//Horizontal X-
|
//Horizontal X-
|
||||||
for(int i = blockX; i >= blockX-block.getSizeHor(); i--){
|
for(int i = blockX; i >= blockX-block.getSizeHor()-1; i--){
|
||||||
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(i, blockY, blockZ))){
|
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(i, blockY, blockZ))){
|
||||||
minX = i+1;
|
minX = i+1;
|
||||||
break;
|
break;
|
||||||
|
@ -47,7 +49,7 @@ public class MultiBlockHelper{
|
||||||
}
|
}
|
||||||
|
|
||||||
//Horizontal Z+
|
//Horizontal Z+
|
||||||
for(int i = blockZ; i < blockZ+block.getSizeHor(); i++){
|
for(int i = blockZ; i < blockZ+block.getSizeHor()+1; i++){
|
||||||
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(blockX, blockY, i))){
|
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(blockX, blockY, i))){
|
||||||
maxZ = i-1;
|
maxZ = i-1;
|
||||||
break;
|
break;
|
||||||
|
@ -56,7 +58,7 @@ public class MultiBlockHelper{
|
||||||
}
|
}
|
||||||
|
|
||||||
//Horizontal Z-
|
//Horizontal Z-
|
||||||
for(int i = blockZ; i >= blockZ-block.getSizeHor(); i--){
|
for(int i = blockZ; i >= blockZ-block.getSizeHor()-1; i--){
|
||||||
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(blockX, blockY, i))){
|
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(blockX, blockY, i))){
|
||||||
minZ = i+1;
|
minZ = i+1;
|
||||||
break;
|
break;
|
||||||
|
@ -65,7 +67,7 @@ public class MultiBlockHelper{
|
||||||
}
|
}
|
||||||
|
|
||||||
//Horizontal Y+
|
//Horizontal Y+
|
||||||
for(int i = blockY; i < blockY+block.getSizeVer(); i++){
|
for(int i = blockY; i < blockY+block.getSizeVer()+1; i++){
|
||||||
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(blockX, i, blockZ))){
|
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(blockX, i, blockZ))){
|
||||||
maxY = i-1;
|
maxY = i-1;
|
||||||
break;
|
break;
|
||||||
|
@ -74,7 +76,7 @@ public class MultiBlockHelper{
|
||||||
}
|
}
|
||||||
|
|
||||||
//Horizontal Y-
|
//Horizontal Y-
|
||||||
for(int i = blockY; i >= blockY-block.getSizeVer(); i--){
|
for(int i = blockY; i >= blockY-block.getSizeVer()-1; i--){
|
||||||
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(blockX, i, blockZ))){
|
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(blockX, i, blockZ))){
|
||||||
minY = i+1;
|
minY = i+1;
|
||||||
break;
|
break;
|
||||||
|
@ -89,7 +91,8 @@ public class MultiBlockHelper{
|
||||||
for(int x = minX; x <= maxX; x++){
|
for(int x = minX; x <= maxX; x++){
|
||||||
for(int y = minY; y <= maxY; y++){
|
for(int y = minY; y <= maxY; y++){
|
||||||
for(int z = minZ; z <= maxZ; z++){
|
for(int z = minZ; z <= maxZ; z++){
|
||||||
if(containsBlock(block.getNeededBlocks(), blockWorld.getBlock(x, y, z)) && maxX+1-minX >= block.getSizeHor() && maxZ+1-minZ >= block.getSizeHor() && maxY+1-minY >= block.getSizeVer()){
|
//Needs to be the exact size, not too small
|
||||||
|
if(containsBlock(block.getNeededBlocks(), blockWorld.getBlock(x, y, z)) && maxX+1-minX == block.getSizeHor() && maxZ+1-minZ == block.getSizeHor() && maxY+1-minY == block.getSizeVer()){
|
||||||
//Add the Block to the List to return
|
//Add the Block to the List to return
|
||||||
blocks.add(new WorldPos(blockWorld, x, y, z));
|
blocks.add(new WorldPos(blockWorld, x, y, z));
|
||||||
//Set the Block to MultiBlock-"State"
|
//Set the Block to MultiBlock-"State"
|
||||||
|
|
|
@ -4,5 +4,11 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
|
||||||
public interface IButtonReactor{
|
public interface IButtonReactor{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a Button in a GUI is pressed
|
||||||
|
* Gets called on the Server, sent from the Client
|
||||||
|
* @param buttonID The button's ID
|
||||||
|
* @param player The Player pressing it
|
||||||
|
*/
|
||||||
void onButtonPressed(int buttonID, EntityPlayer player);
|
void onButtonPressed(int buttonID, EntityPlayer player);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,5 +4,11 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
|
||||||
public interface INumberReactor{
|
public interface INumberReactor{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a Number gets received after typing it in in the GUI
|
||||||
|
* @param text The number that was sent (I don't remember why I called it text. Had a reason though.)
|
||||||
|
* @param textID The ID (meaning the place in the GUI) of the number typed in
|
||||||
|
* @param player The Player doing it
|
||||||
|
*/
|
||||||
void onNumberReceived(int text, int textID, EntityPlayer player);
|
void onNumberReceived(int text, int textID, EntityPlayer player);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,19 @@ package ellpeck.actuallyadditions.network.sync;
|
||||||
|
|
||||||
public interface IPacketSyncerToClient{
|
public interface IPacketSyncerToClient{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The values that should be sent to the Client
|
||||||
|
*/
|
||||||
int[] getValues();
|
int[] getValues();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Values on the Client
|
||||||
|
* @param values The Values
|
||||||
|
*/
|
||||||
void setValues(int[] values);
|
void setValues(int[] values);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends the Update
|
||||||
|
*/
|
||||||
void sendUpdate();
|
void sendUpdate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,6 +112,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
if(!worldObj.isRemote){
|
if(!worldObj.isRemote){
|
||||||
this.initVars();
|
this.initVars();
|
||||||
|
|
||||||
|
//Is Block not powered by Redstone?
|
||||||
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){
|
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){
|
||||||
if(!(this.sideToPull == this.sideToPut && this.slotToPullStart == this.slotToPutStart && this.slotToPullEnd == this.slotToPutEnd)){
|
if(!(this.sideToPull == this.sideToPut && this.slotToPullStart == this.slotToPutStart && this.slotToPullEnd == this.slotToPutEnd)){
|
||||||
if(sideToPull != -1 && this.placeToPull instanceof IInventory) this.pull();
|
if(sideToPull != -1 && this.placeToPull instanceof IInventory) this.pull();
|
||||||
|
@ -119,6 +120,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Update the Client
|
||||||
if(this.sideToPut != this.lastPutSide || this.sideToPull != this.lastPullSide || this.slotToPullStart != this.lastPullStart || this.slotToPullEnd != this.lastPullEnd || this.slotToPutStart != this.lastPutStart || this.slotToPutEnd != this.lastPutEnd || this.isPullWhitelist != lastPullWhite || this.isPutWhitelist != this.lastPutWhite){
|
if(this.sideToPut != this.lastPutSide || this.sideToPull != this.lastPullSide || this.slotToPullStart != this.lastPullStart || this.slotToPullEnd != this.lastPullEnd || this.slotToPutStart != this.lastPutStart || this.slotToPutEnd != this.lastPutEnd || this.isPullWhitelist != lastPullWhite || this.isPutWhitelist != this.lastPutWhite){
|
||||||
this.lastPutSide = this.sideToPut;
|
this.lastPutSide = this.sideToPut;
|
||||||
this.lastPullSide = this.sideToPull;
|
this.lastPullSide = this.sideToPull;
|
||||||
|
@ -133,24 +135,40 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pulls Items from the specified Slots on the specified Side
|
||||||
|
*/
|
||||||
public void pull(){
|
public void pull(){
|
||||||
|
//The Inventory to pull from
|
||||||
IInventory theInventory = (IInventory)placeToPull;
|
IInventory theInventory = (IInventory)placeToPull;
|
||||||
|
//Does the Inventory even have Slots!?
|
||||||
if(theInventory.getSizeInventory() > 0){
|
if(theInventory.getSizeInventory() > 0){
|
||||||
|
//The slot currently pulling from (for later)
|
||||||
int theSlotToPull = this.slotToPullStart;
|
int theSlotToPull = this.slotToPullStart;
|
||||||
|
//The amount of Items that can fit into one slot of the inventory
|
||||||
int maxSize = theInventory.getInventoryStackLimit();
|
int maxSize = theInventory.getInventoryStackLimit();
|
||||||
|
//If the Inventory is ISided, deal with that
|
||||||
ISidedInventory theSided = null;
|
ISidedInventory theSided = null;
|
||||||
if(theInventory instanceof ISidedInventory) theSided = (ISidedInventory)theInventory;
|
if(theInventory instanceof ISidedInventory) theSided = (ISidedInventory)theInventory;
|
||||||
|
//If can be pulled (for later)
|
||||||
boolean can = false;
|
boolean can = false;
|
||||||
|
|
||||||
|
//The Stack that is pulled (for later)
|
||||||
ItemStack theStack = null;
|
ItemStack theStack = null;
|
||||||
|
//Go through all of the specified Slots
|
||||||
for(int i = Math.max(theSlotToPull, 0); i < Math.min(this.slotToPullEnd, theInventory.getSizeInventory()); i++){
|
for(int i = Math.max(theSlotToPull, 0); i < Math.min(this.slotToPullEnd, theInventory.getSizeInventory()); i++){
|
||||||
|
//Temporary Stack for storage
|
||||||
ItemStack tempStack = theInventory.getStackInSlot(i);
|
ItemStack tempStack = theInventory.getStackInSlot(i);
|
||||||
if(tempStack != null){
|
if(tempStack != null){
|
||||||
|
//Set maxSize to the max Size of the temporary stack if it's smaller than the Inventory's Max Size
|
||||||
if(tempStack.getMaxStackSize() < this.getInventoryStackLimit()) maxSize = tempStack.getMaxStackSize();
|
if(tempStack.getMaxStackSize() < this.getInventoryStackLimit()) maxSize = tempStack.getMaxStackSize();
|
||||||
else maxSize = this.getInventoryStackLimit();
|
else maxSize = this.getInventoryStackLimit();
|
||||||
}
|
}
|
||||||
|
//If ESD has enough Space & Item in question is on whitelist
|
||||||
if(tempStack != null && (this.slots[0] == null || (tempStack.isItemEqual(this.slots[0]) && this.slots[0].stackSize < maxSize)) && this.checkFilters(tempStack, true, isPullWhitelist)){
|
if(tempStack != null && (this.slots[0] == null || (tempStack.isItemEqual(this.slots[0]) && this.slots[0].stackSize < maxSize)) && this.checkFilters(tempStack, true, isPullWhitelist)){
|
||||||
|
//Deal with ISided
|
||||||
if(theSided != null){
|
if(theSided != null){
|
||||||
|
//Check if Item can be inserted from any Side (Because Sidedness gets ignored!)
|
||||||
for(int j = 0; j < 5; j++){
|
for(int j = 0; j < 5; j++){
|
||||||
if(theSided.canExtractItem(i, tempStack, j)){
|
if(theSided.canExtractItem(i, tempStack, j)){
|
||||||
theStack = tempStack;
|
theStack = tempStack;
|
||||||
|
@ -160,31 +178,40 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Deal with IInventory
|
||||||
else{
|
else{
|
||||||
theStack = tempStack;
|
theStack = tempStack;
|
||||||
theSlotToPull = i;
|
theSlotToPull = i;
|
||||||
can = true;
|
can = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Stop if it can already pull
|
||||||
if(can) break;
|
if(can) break;
|
||||||
}
|
}
|
||||||
|
//If pull can be done
|
||||||
if(can){
|
if(can){
|
||||||
|
//If ESD already has Items
|
||||||
if(this.slots[0] != null){
|
if(this.slots[0] != null){
|
||||||
if(theStack.isItemEqual(this.slots[0])){
|
if(theStack.isItemEqual(this.slots[0])){
|
||||||
|
//If the StackSize is smaller than the space the ESD has left
|
||||||
if(theStack.stackSize <= maxSize - this.slots[0].stackSize){
|
if(theStack.stackSize <= maxSize - this.slots[0].stackSize){
|
||||||
this.slots[0].stackSize += theStack.stackSize;
|
this.slots[0].stackSize += theStack.stackSize;
|
||||||
theInventory.setInventorySlotContents(theSlotToPull, null);
|
theInventory.setInventorySlotContents(theSlotToPull, null);
|
||||||
}
|
}
|
||||||
|
//If the StackSize is bigger than what fits into the Inventory
|
||||||
else if(theStack.stackSize > maxSize - this.slots[0].stackSize){
|
else if(theStack.stackSize > maxSize - this.slots[0].stackSize){
|
||||||
theInventory.decrStackSize(theSlotToPull, maxSize - this.slots[0].stackSize);
|
theInventory.decrStackSize(theSlotToPull, maxSize - this.slots[0].stackSize);
|
||||||
this.slots[0].stackSize = maxSize;
|
this.slots[0].stackSize = maxSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//If ESD is empty
|
||||||
else{
|
else{
|
||||||
ItemStack toBePut = theStack.copy();
|
ItemStack toBePut = theStack.copy();
|
||||||
if(maxSize < toBePut.stackSize) toBePut.stackSize = maxSize;
|
if(maxSize < toBePut.stackSize) toBePut.stackSize = maxSize;
|
||||||
|
//Actually puts the Item
|
||||||
this.setInventorySlotContents(0, toBePut);
|
this.setInventorySlotContents(0, toBePut);
|
||||||
|
//Removes the Item from the inventory getting pulled from
|
||||||
if(theStack.stackSize == toBePut.stackSize) theInventory.setInventorySlotContents(theSlotToPull, null);
|
if(theStack.stackSize == toBePut.stackSize) theInventory.setInventorySlotContents(theSlotToPull, null);
|
||||||
else theInventory.decrStackSize(theSlotToPull, toBePut.stackSize);
|
else theInventory.decrStackSize(theSlotToPull, toBePut.stackSize);
|
||||||
}
|
}
|
||||||
|
@ -192,6 +219,10 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts Items into the specified Slots at the specified Side
|
||||||
|
* (Check pull() for Description, similar to this)
|
||||||
|
*/
|
||||||
public void put(){
|
public void put(){
|
||||||
IInventory theInventory = (IInventory)placeToPut;
|
IInventory theInventory = (IInventory)placeToPut;
|
||||||
if(theInventory.getSizeInventory() > 0){
|
if(theInventory.getSizeInventory() > 0){
|
||||||
|
@ -253,6 +284,13 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the Whitelist/Blacklist to see if Item fits
|
||||||
|
* @param stack The Stack to check for
|
||||||
|
* @param isPull If we're pulling or putting
|
||||||
|
* @param isWhitelist If it's set to white- or Blacklist
|
||||||
|
* @return Is Item on White-/Blacklist?
|
||||||
|
*/
|
||||||
public boolean checkFilters(ItemStack stack, boolean isPull, boolean isWhitelist){
|
public boolean checkFilters(ItemStack stack, boolean isPull, boolean isWhitelist){
|
||||||
if(!this.isAdvanced) return true;
|
if(!this.isAdvanced) return true;
|
||||||
|
|
||||||
|
@ -265,11 +303,16 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
return !isWhitelist;
|
return !isWhitelist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets all of the relevant variables
|
||||||
|
*/
|
||||||
public void initVars(){
|
public void initVars(){
|
||||||
|
|
||||||
|
//Gets the Place to put and Pull
|
||||||
this.placeToPull = WorldUtil.getTileEntityFromSide(WorldUtil.getDirectionByRotatingSide(this.sideToPull), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
this.placeToPull = WorldUtil.getTileEntityFromSide(WorldUtil.getDirectionByRotatingSide(this.sideToPull), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
||||||
this.placeToPut = WorldUtil.getTileEntityFromSide(WorldUtil.getDirectionByRotatingSide(this.sideToPut), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
this.placeToPut = WorldUtil.getTileEntityFromSide(WorldUtil.getDirectionByRotatingSide(this.sideToPut), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
||||||
|
|
||||||
|
//Resets the Variables
|
||||||
if(this.placeToPull instanceof IInventory){
|
if(this.placeToPull instanceof IInventory){
|
||||||
if(this.slotToPullEnd <= 0) this.slotToPullEnd = ((IInventory)this.placeToPull).getSizeInventory();
|
if(this.slotToPullEnd <= 0) this.slotToPullEnd = ((IInventory)this.placeToPull).getSizeInventory();
|
||||||
}
|
}
|
||||||
|
@ -289,6 +332,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Reset the Slots
|
||||||
if(buttonID == 0 || buttonID == 1){
|
if(buttonID == 0 || buttonID == 1){
|
||||||
this.slotToPutStart = 0;
|
this.slotToPutStart = 0;
|
||||||
this.slotToPutEnd = 0;
|
this.slotToPutEnd = 0;
|
||||||
|
|
Loading…
Reference in a new issue