use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.
the class LinkageHandler method canMinecartTick.
@SubscribeEvent
public void canMinecartTick(EntityEvent.CanUpdate event) {
if (event.getEntity() instanceof EntityMinecart) {
EntityMinecart cart = (EntityMinecart) event.getEntity();
Train train = Train.getTrain(cart);
for (EntityCartWorldspike worldspike : train.getCarts(EntityCartWorldspike.class)) {
if (worldspike.hasActiveTicket()) {
event.setCanUpdate(true);
return;
}
}
}
}
use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.
the class Train method buildTrain.
private void buildTrain(@Nullable EntityMinecart prev, EntityMinecart next) {
_addLink(prev, next);
LinkageManager lm = LinkageManager.instance();
EntityMinecart linkA = lm.getLinkedCartA(next);
EntityMinecart linkB = lm.getLinkedCartB(next);
if (linkA != null && linkA != prev && !containsCart(linkA))
buildTrain(next, linkA);
if (linkB != null && linkB != prev && !containsCart(linkB))
buildTrain(next, linkB);
}
use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.
the class LinkageManager method numLinkedCarts.
private int numLinkedCarts(EntityMinecart prev, EntityMinecart next) {
int count = 1;
EntityMinecart linkA = getLinkedCartA(next);
EntityMinecart linkB = getLinkedCartB(next);
if (linkA != null && linkA != prev)
count += numLinkedCarts(next, linkA);
if (linkB != null && linkB != prev)
count += numLinkedCarts(next, linkB);
return count;
}
use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.
the class CartBaseEnergy method extractEnergy.
@Override
public double extractEnergy(Object source, double amount, int tier, boolean ignoreTransferLimit, boolean simulate, boolean passAlong) {
if (tier < getTier())
return 0;
if (!ignoreTransferLimit)
amount = Math.min(amount, getTransferLimit());
double e = getEnergy();
double provide = Math.min(amount, e);
e -= provide;
if (e < 0)
e = 0;
if (!simulate)
setEnergy(e);
if (!passAlong)
return provide;
ILinkageManager lm = CartToolsAPI.getLinkageManager(worldObj);
EntityMinecart linkedCart = lm.getLinkedCartA(this);
if (provide < amount && linkedCart != source && linkedCart instanceof IEnergyTransfer)
provide += ((IEnergyTransfer) linkedCart).extractEnergy(this, amount - provide, tier, ignoreTransferLimit, simulate, true);
linkedCart = lm.getLinkedCartB(this);
if (provide < amount && linkedCart != source && linkedCart instanceof IEnergyTransfer)
provide += ((IEnergyTransfer) linkedCart).extractEnergy(this, amount - provide, tier, ignoreTransferLimit, simulate, true);
return provide;
}
use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.
the class TileItemManipulator method processCart.
@Override
protected void processCart(EntityMinecart cart) {
chests.clear();
chests.add(invBuffer);
chests.addAll(invCache.getAdjacentInventories());
InventoryComposite cartInv = InventoryComposite.of(InventoryFactory.get(cart, getFacing().getOpposite()));
if (cartInv.isEmpty()) {
sendCart(cart);
return;
}
this.cart = cartInv;
switch(getMode()) {
case TRANSFER:
{
Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
filterManifest.entrySet().stream().filter(entry -> transferredItems.count(entry.getElement()) < entry.getCount()).anyMatch(entry -> {
ItemStack moved = InvTools.moveOneItem(getSource(), getDestination(), StackFilters.matches(entry.getElement().get()));
if (!InvTools.isEmpty(moved)) {
setProcessing(true);
transferredItems.add(entry.getElement());
return true;
}
return false;
});
break;
}
case STOCK:
{
Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
Multiset<StackKey> destManifest = InvTools.createManifest(getDestination(), filterManifest.elementSet());
moveItem(filterManifest.entrySet().stream().filter(entry -> destManifest.count(entry.getElement()) < entry.getCount()));
break;
}
case EXCESS:
{
Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
Multiset<StackKey> sourceManifest = InvTools.createManifest(getSource(), filterManifest.elementSet());
moveItem(filterManifest.entrySet().stream().filter(entry -> sourceManifest.count(entry.getElement()) > entry.getCount()));
if (!isProcessing()) {
Predicate<ItemStack> keep = filterManifest.elementSet().stream().map(e -> StackFilters.matches(e.get())).reduce(StackFilters.none(), Predicate::or);
ItemStack moved = InvTools.moveOneItemExcept(getSource(), getDestination(), keep);
itemMoved(moved);
}
break;
}
case ALL:
{
Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
if (filterManifest.isEmpty()) {
ItemStack moved = InvTools.moveOneItem(getSource(), getDestination());
itemMoved(moved);
} else {
moveItem(filterManifest.entrySet().stream());
}
break;
}
}
}
Aggregations