Did lots of Comment stuff on the ESD to make it more understandable

This commit is contained in:
Ellpeck 2015-07-22 18:24:43 +02:00
parent 55f4f07065
commit 2dbaaf24dd
5 changed files with 77 additions and 8 deletions

View file

@ -28,9 +28,11 @@ public class MultiBlockHelper{
//Setting Min and Max Boundaries of the MultiBlock
//Horizontal X+
for(int i = blockX; i < blockX+block.getSizeHor(); i++){
//Horizontal X+ +1/-1 to prevent bigger MultiBlocks from working too
for(int i = blockX; i < blockX+block.getSizeHor()+1; i++){
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;
break;
}
@ -38,7 +40,7 @@ public class MultiBlockHelper{
}
//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))){
minX = i+1;
break;
@ -47,7 +49,7 @@ public class MultiBlockHelper{
}
//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))){
maxZ = i-1;
break;
@ -56,7 +58,7 @@ public class MultiBlockHelper{
}
//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))){
minZ = i+1;
break;
@ -65,7 +67,7 @@ public class MultiBlockHelper{
}
//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))){
maxY = i-1;
break;
@ -74,7 +76,7 @@ public class MultiBlockHelper{
}
//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))){
minY = i+1;
break;
@ -89,7 +91,8 @@ public class MultiBlockHelper{
for(int x = minX; x <= maxX; x++){
for(int y = minY; y <= maxY; y++){
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
blocks.add(new WorldPos(blockWorld, x, y, z));
//Set the Block to MultiBlock-"State"

View file

@ -4,5 +4,11 @@ import net.minecraft.entity.player.EntityPlayer;
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);
}

View file

@ -4,5 +4,11 @@ import net.minecraft.entity.player.EntityPlayer;
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);
}

View file

@ -2,9 +2,19 @@ package ellpeck.actuallyadditions.network.sync;
public interface IPacketSyncerToClient{
/**
* @return The values that should be sent to the Client
*/
int[] getValues();
/**
* Sets the Values on the Client
* @param values The Values
*/
void setValues(int[] values);
/**
* Sends the Update
*/
void sendUpdate();
}

View file

@ -112,6 +112,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
if(!worldObj.isRemote){
this.initVars();
//Is Block not powered by Redstone?
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){
if(!(this.sideToPull == this.sideToPut && this.slotToPullStart == this.slotToPutStart && this.slotToPullEnd == this.slotToPutEnd)){
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){
this.lastPutSide = this.sideToPut;
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(){
//The Inventory to pull from
IInventory theInventory = (IInventory)placeToPull;
//Does the Inventory even have Slots!?
if(theInventory.getSizeInventory() > 0){
//The slot currently pulling from (for later)
int theSlotToPull = this.slotToPullStart;
//The amount of Items that can fit into one slot of the inventory
int maxSize = theInventory.getInventoryStackLimit();
//If the Inventory is ISided, deal with that
ISidedInventory theSided = null;
if(theInventory instanceof ISidedInventory) theSided = (ISidedInventory)theInventory;
//If can be pulled (for later)
boolean can = false;
//The Stack that is pulled (for later)
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++){
//Temporary Stack for storage
ItemStack tempStack = theInventory.getStackInSlot(i);
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();
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)){
//Deal with ISided
if(theSided != null){
//Check if Item can be inserted from any Side (Because Sidedness gets ignored!)
for(int j = 0; j < 5; j++){
if(theSided.canExtractItem(i, tempStack, j)){
theStack = tempStack;
@ -160,31 +178,40 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
}
}
}
//Deal with IInventory
else{
theStack = tempStack;
theSlotToPull = i;
can = true;
}
}
//Stop if it can already pull
if(can) break;
}
//If pull can be done
if(can){
//If ESD already has Items
if(this.slots[0] != null){
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){
this.slots[0].stackSize += theStack.stackSize;
theInventory.setInventorySlotContents(theSlotToPull, null);
}
//If the StackSize is bigger than what fits into the Inventory
else if(theStack.stackSize > maxSize - this.slots[0].stackSize){
theInventory.decrStackSize(theSlotToPull, maxSize - this.slots[0].stackSize);
this.slots[0].stackSize = maxSize;
}
}
}
//If ESD is empty
else{
ItemStack toBePut = theStack.copy();
if(maxSize < toBePut.stackSize) toBePut.stackSize = maxSize;
//Actually puts the Item
this.setInventorySlotContents(0, toBePut);
//Removes the Item from the inventory getting pulled from
if(theStack.stackSize == toBePut.stackSize) theInventory.setInventorySlotContents(theSlotToPull, null);
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(){
IInventory theInventory = (IInventory)placeToPut;
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){
if(!this.isAdvanced) return true;
@ -265,11 +303,16 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
return !isWhitelist;
}
/**
* Sets all of the relevant variables
*/
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.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.slotToPullEnd <= 0) this.slotToPullEnd = ((IInventory)this.placeToPull).getSizeInventory();
}
@ -289,6 +332,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
return;
}
//Reset the Slots
if(buttonID == 0 || buttonID == 1){
this.slotToPutStart = 0;
this.slotToPutEnd = 0;