ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java

107 lines
3.5 KiB
Java
Raw Normal View History

2015-10-10 02:51:06 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("TileEntityRangedCollector.java") is part of the Actually Additions mod for Minecraft.
2015-10-10 02:51:06 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-10-10 02:51:06 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2015-10-10 02:51:06 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.tile;
2015-10-10 02:51:06 +02:00
2018-02-12 01:44:15 +01:00
import java.util.ArrayList;
import java.util.List;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
2015-10-10 02:51:06 +02:00
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumParticleTypes;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.WorldServer;
2015-10-10 02:51:06 +02:00
public class TileEntityRangedCollector extends TileEntityInventoryBase implements IButtonReactor{
2015-10-10 02:51:06 +02:00
2015-12-01 19:48:09 +01:00
public static final int RANGE = 6;
public FilterSettings filter = new FilterSettings(12, true, true, false, false, 0, -1000);
2015-10-10 02:51:06 +02:00
public TileEntityRangedCollector(){
super(6, "rangedCollector");
2015-10-10 02:51:06 +02:00
}
2016-02-01 17:49:55 +01:00
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type);
this.filter.writeToNBT(compound, "Filter");
2016-02-01 17:49:55 +01:00
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type);
this.filter.readFromNBT(compound, "Filter");
2016-02-01 17:49:55 +01:00
}
2015-10-10 02:51:06 +02:00
@Override
public boolean isRedstoneToggle(){
return true;
}
@Override
public void activateOnPulse(){
2018-02-12 01:44:15 +01:00
List<EntityItem> items = this.world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(this.pos.getX()-RANGE, this.pos.getY()-RANGE, this.pos.getZ()-RANGE, this.pos.getX()+RANGE, this.pos.getY()+RANGE, this.pos.getZ()+RANGE));
if(!items.isEmpty()){
for(EntityItem item : items){
if(!item.isDead && !item.cannotPickup() && StackUtil.isValid(item.getItem())){
ItemStack toAdd = item.getItem().copy();
if(this.filter.check(toAdd)){
ArrayList<ItemStack> checkList = new ArrayList<ItemStack>();
checkList.add(toAdd);
if(WorldUtil.addToInventory(this.slots, checkList, false)){
WorldUtil.addToInventory(this.slots, checkList, true);
((WorldServer)this.world).spawnParticle(EnumParticleTypes.CLOUD, false, item.posX, item.posY+0.45F, item.posZ, 5, 0, 0, 0, 0.03D);
item.setDead();
2015-10-10 02:51:06 +02:00
}
}
}
}
}
}
@Override
public void updateEntity(){
super.updateEntity();
if(!this.world.isRemote){
if(!this.isRedstonePowered && !this.isPulseMode){
this.activateOnPulse();
}
2015-10-10 02:51:06 +02:00
if(this.filter.needsUpdateSend() && this.sendUpdateWithInterval()){
this.filter.updateLasts();
2015-10-10 02:51:06 +02:00
}
}
}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack){
2016-02-01 17:49:55 +01:00
return false;
2015-10-18 15:31:01 +02:00
}
2015-10-10 02:51:06 +02:00
@Override
public boolean canExtractItem(int slot, ItemStack stack){
return true;
2015-10-10 02:51:06 +02:00
}
@Override
public void onButtonPressed(int buttonID, EntityPlayer player){
this.filter.onButtonPressed(buttonID);
2015-10-10 02:51:06 +02:00
}
}