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

100 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;
2018-08-10 05:04:07 +02:00
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
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() {
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 (StackUtil.canAddAll(inv, checkList, false)) {
2018-06-23 18:39:59 +02:00
StackUtil.addAll(inv, checkList, false);
((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
2018-08-10 05:04:07 +02:00
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> !automation;
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
}
}