Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2054c2afe3 | |||
| 69650e2bef | |||
| 1a576705fe | |||
| 27a3f70f0b |
@@ -140,6 +140,27 @@ public final class ItemPart extends AEBaseItem implements IPartItem, IItemGroup
|
||||
return AEApi.instance().partHelper().placeBus(player.getHeldItem(hand), pos, side, player, hand, w);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBookEnchantable(ItemStack itemstack1, ItemStack itemstack2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnchantable(ItemStack stack) {
|
||||
if (getTypeByStack(stack) == PartType.IDENTITY_ANNIHILATION_PLANE) {
|
||||
return true;
|
||||
}
|
||||
return super.isEnchantable(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemEnchantability(ItemStack stack) {
|
||||
if (getTypeByStack(stack) == PartType.IDENTITY_ANNIHILATION_PLANE) {
|
||||
return 10;
|
||||
}
|
||||
return super.getItemEnchantability(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public String getTranslationKey(final ItemStack is) {
|
||||
|
||||
@@ -330,6 +330,12 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab
|
||||
return changed;
|
||||
}
|
||||
|
||||
private void handleOverflow(final ItemStack stack, final IAEItemStack overflow) {
|
||||
if (overflow.getStackSize() != 0L) {
|
||||
stack.setCount((int) overflow.getStackSize());
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isAnnihilationPlane(final TileEntity blockTileEntity, final AEPartLocation side) {
|
||||
if (blockTileEntity instanceof IPartHost) {
|
||||
final IPart p = ((IPartHost) blockTileEntity).getPart(side);
|
||||
@@ -371,7 +377,7 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab
|
||||
if (hasPower && canStore) {
|
||||
if (modulate) {
|
||||
energy.extractAEPower(requiredPower, Actionable.MODULATE, PowerMultiplier.CONFIG);
|
||||
this.breakBlockAndStoreItems(w, pos);
|
||||
this.breakBlockAndStoreItems(w, pos, items);
|
||||
AppEng.proxy.sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 64, w,
|
||||
new PacketTransitionEffect(pos.getX(), pos.getY(), pos.getZ(), this.getSide(), true));
|
||||
} else {
|
||||
@@ -471,14 +477,12 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab
|
||||
return canStore;
|
||||
}
|
||||
|
||||
private void breakBlockAndStoreItems(final WorldServer w, final BlockPos pos) {
|
||||
w.destroyBlock(pos, true);
|
||||
|
||||
final AxisAlignedBB box = new AxisAlignedBB(pos).grow(0.2);
|
||||
for (final Object ei : w.getEntitiesWithinAABB(EntityItem.class, box)) {
|
||||
if (ei instanceof EntityItem) {
|
||||
final EntityItem entityItem = (EntityItem) ei;
|
||||
this.storeEntityItem(entityItem);
|
||||
private void breakBlockAndStoreItems(final WorldServer w, final BlockPos pos, final List<ItemStack> drops) {
|
||||
w.destroyBlock(pos, false);
|
||||
for (final ItemStack drop : drops) {
|
||||
IAEItemStack overflow = storeItemStack(drop);
|
||||
if (overflow != null) {
|
||||
handleOverflow(drop, overflow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,23 +19,27 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.items.parts.PartModels;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.init.Enchantments;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class PartIdentityAnnihilationPlane extends PartAnnihilationPlane {
|
||||
@@ -47,26 +51,33 @@ public class PartIdentityAnnihilationPlane extends PartAnnihilationPlane {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
private static final float SILK_TOUCH_FACTOR = 16;
|
||||
|
||||
public PartIdentityAnnihilationPlane(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAnnihilationPlane(final TileEntity blockTileEntity, final AEPartLocation side) {
|
||||
if (blockTileEntity instanceof IPartHost) {
|
||||
final IPart p = ((IPartHost) blockTileEntity).getPart(side);
|
||||
return p != null && p.getClass() == this.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float calculateEnergyUsage(final WorldServer w, final BlockPos pos, final List<ItemStack> items) {
|
||||
final float requiredEnergy = super.calculateEnergyUsage(w, pos, items);
|
||||
float requiredEnergy = super.calculateEnergyUsage(w, pos, items);
|
||||
|
||||
return requiredEnergy * SILK_TOUCH_FACTOR;
|
||||
final ItemStack stack = getItemStack();
|
||||
|
||||
// Give plane only a (100 / (level + 1))% chance to use energy.
|
||||
// This is similar to vanilla Unbreaking behaviour for tools.
|
||||
final int unbreaking = getEnchantmentLevel(Enchantments.UNBREAKING, stack);
|
||||
if (unbreaking > 0) {
|
||||
int randomNumber = w.rand.nextInt(unbreaking + 1);
|
||||
if (randomNumber > 0) return 0;
|
||||
}
|
||||
|
||||
// Increase power cost from other enchantments.
|
||||
final int levelSum = EnchantmentHelper.getEnchantments(stack).values().stream().reduce(0, Integer::sum);
|
||||
if (levelSum > 0) {
|
||||
final int efficiency = getEnchantmentLevel(Enchantments.EFFICIENCY, stack);
|
||||
requiredEnergy *= 8 * (levelSum - efficiency);
|
||||
// Reduce total energy usage incurred by other enchantments by 15% per Efficiency level.
|
||||
requiredEnergy *= (float) Math.pow(0.85F, efficiency);
|
||||
}
|
||||
return requiredEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,7 +85,13 @@ public class PartIdentityAnnihilationPlane extends PartAnnihilationPlane {
|
||||
final FakePlayer fakePlayer = FakePlayerFactory.getMinecraft(w);
|
||||
final IBlockState state = w.getBlockState(pos);
|
||||
|
||||
if (state.getBlock().canSilkHarvest(w, pos, state, fakePlayer)) {
|
||||
final ItemStack prevItem = fakePlayer.getHeldItem(EnumHand.MAIN_HAND);
|
||||
final ItemStack stack = getItemStack();
|
||||
fakePlayer.setHeldItem(EnumHand.MAIN_HAND, stack);
|
||||
|
||||
final int fortune = getEnchantmentLevel(Enchantments.FORTUNE, stack);
|
||||
|
||||
if (state.getBlock().canSilkHarvest(w, pos, state, fakePlayer) && fortune <= 0) {
|
||||
final List<ItemStack> out = new ArrayList<>(1);
|
||||
final Item item = Item.getItemFromBlock(state.getBlock());
|
||||
|
||||
@@ -85,16 +102,32 @@ public class PartIdentityAnnihilationPlane extends PartAnnihilationPlane {
|
||||
}
|
||||
final ItemStack itemstack = new ItemStack(item, 1, meta);
|
||||
out.add(itemstack);
|
||||
|
||||
final float chance = ForgeEventFactory.fireBlockHarvesting(out, w, pos, state, 0, 1.0F, true, fakePlayer);
|
||||
fakePlayer.setHeldItem(EnumHand.MAIN_HAND, prevItem);
|
||||
if (chance == 1.0F) return out;
|
||||
return out.stream().filter($ -> w.rand.nextFloat() <= chance).collect(Collectors.toList());
|
||||
}
|
||||
fakePlayer.setHeldItem(EnumHand.MAIN_HAND, prevItem);
|
||||
return out;
|
||||
} else {
|
||||
return super.obtainBlockDrops(w, pos);
|
||||
}
|
||||
final NonNullList<ItemStack> drops = NonNullList.create();
|
||||
state.getBlock().getDrops(drops, w, pos, state, fortune);
|
||||
|
||||
final float chance = ForgeEventFactory.fireBlockHarvesting(drops, w, pos, state, fortune, 1.0F, false, fakePlayer);
|
||||
fakePlayer.setHeldItem(EnumHand.MAIN_HAND, prevItem);
|
||||
if (chance == 1.0F) return drops;
|
||||
return drops.stream().filter($ -> w.rand.nextFloat() <= chance).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.getConnections(), this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
private static int getEnchantmentLevel(final Enchantment enchantment, final ItemStack stack) {
|
||||
if (enchantment == null) return 0;
|
||||
return EnchantmentHelper.getEnchantmentLevel(enchantment, stack);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user