pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.items.tools.powered;
|
||||
|
||||
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -32,36 +31,30 @@ import appeng.core.sync.packets.PacketLightning;
|
||||
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolChargedStaff extends AEBasePoweredItem {
|
||||
|
||||
public class ToolChargedStaff extends AEBasePoweredItem
|
||||
{
|
||||
public ToolChargedStaff(Item.Properties props) {
|
||||
super(AEConfig.instance().getChargedStaffBattery(), props);
|
||||
}
|
||||
|
||||
public ToolChargedStaff(Item.Properties props)
|
||||
{
|
||||
super( AEConfig.instance().getChargedStaffBattery(), props );
|
||||
}
|
||||
@Override
|
||||
public boolean hitEntity(final ItemStack item, final LivingEntity target, final LivingEntity hitter) {
|
||||
if (this.getAECurrentPower(item) > 300) {
|
||||
this.extractAEPower(item, 300, Actionable.MODULATE);
|
||||
if (Platform.isServer()) {
|
||||
for (int x = 0; x < 2; x++) {
|
||||
final AxisAlignedBB entityBoundingBox = target.getBoundingBox();
|
||||
final float dx = (float) (Platform.getRandomFloat() * target.getWidth() + entityBoundingBox.minX);
|
||||
final float dy = (float) (Platform.getRandomFloat() * target.getHeight() + entityBoundingBox.minY);
|
||||
final float dz = (float) (Platform.getRandomFloat() * target.getWidth() + entityBoundingBox.minZ);
|
||||
AppEng.proxy.sendToAllNearExcept(null, dx, dy, dz, 32.0, target.world,
|
||||
new PacketLightning(dx, dy, dz));
|
||||
}
|
||||
}
|
||||
target.attackEntityFrom(DamageSource.MAGIC, 6);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hitEntity( final ItemStack item, final LivingEntity target, final LivingEntity hitter )
|
||||
{
|
||||
if( this.getAECurrentPower( item ) > 300 )
|
||||
{
|
||||
this.extractAEPower( item, 300, Actionable.MODULATE );
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
for( int x = 0; x < 2; x++ )
|
||||
{
|
||||
final AxisAlignedBB entityBoundingBox = target.getBoundingBox();
|
||||
final float dx = (float) ( Platform.getRandomFloat() * target.getWidth() + entityBoundingBox.minX );
|
||||
final float dy = (float) ( Platform.getRandomFloat() * target.getHeight() + entityBoundingBox.minY );
|
||||
final float dz = (float) ( Platform.getRandomFloat() * target.getWidth() + entityBoundingBox.minZ );
|
||||
AppEng.proxy.sendToAllNearExcept( null, dx, dy, dz, 32.0, target.world, new PacketLightning( dx, dy, dz ) );
|
||||
}
|
||||
}
|
||||
target.attackEntityFrom( DamageSource.MAGIC, 6 );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,30 @@
|
||||
|
||||
package appeng.items.tools.powered;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.SnowballItem;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -48,311 +72,239 @@ import appeng.me.helpers.BaseActionSource;
|
||||
import appeng.tile.misc.TilePaint;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.SnowballItem;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
import java.util.*;
|
||||
public class ToolColorApplicator extends AEBasePoweredItem
|
||||
implements IStorageCell<IAEItemStack>, IItemGroup, IBlockTool, IMouseWheelItem {
|
||||
|
||||
private static final Map<Integer, AEColor> ORE_TO_COLOR = new HashMap<>();
|
||||
|
||||
public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCell<IAEItemStack>, IItemGroup, IBlockTool, IMouseWheelItem
|
||||
{
|
||||
private static final String TAG_COLOR = "color";
|
||||
|
||||
private static final Map<Integer, AEColor> ORE_TO_COLOR = new HashMap<>();
|
||||
static {
|
||||
for (final AEColor color : AEColor.VALID_COLORS) {
|
||||
final String dyeName = color.dye.getTranslationKey();
|
||||
final String oreDictName = "dye" + WordUtils.capitalize(dyeName);
|
||||
// FIXME final int oreDictId = OreDictionary.getOreID( oreDictName );
|
||||
|
||||
private static final String TAG_COLOR = "color";
|
||||
// FIXME ORE_TO_COLOR.put( oreDictId, color );
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
for( final AEColor color : AEColor.VALID_COLORS )
|
||||
{
|
||||
final String dyeName = color.dye.getTranslationKey();
|
||||
final String oreDictName = "dye" + WordUtils.capitalize( dyeName );
|
||||
// FIXME final int oreDictId = OreDictionary.getOreID( oreDictName );
|
||||
public ToolColorApplicator(Item.Properties props) {
|
||||
super(AEConfig.instance().getColorApplicatorBattery(), props);
|
||||
addPropertyOverride(new ResourceLocation(AppEng.MOD_ID, "colored"), (itemStack, world, entity) -> {
|
||||
// If the stack has no color, don't use the colored model since the impact of
|
||||
// calling getColor
|
||||
// for every quad is extremely high, if the stack tries to re-search its
|
||||
// inventory for a new
|
||||
// paintball everytime
|
||||
AEColor col = getActiveColor(itemStack);
|
||||
return (col != null) ? 1 : 0;
|
||||
});
|
||||
}
|
||||
|
||||
// FIXME ORE_TO_COLOR.put( oreDictId, color );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public ActionResultType onItemUse(PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side, float hitX,
|
||||
float hitY, float hitZ) {
|
||||
return this.onItemUse(p.getHeldItem(hand), p, w, pos, hand, side, hitX, hitY, hitZ);
|
||||
}
|
||||
|
||||
public ToolColorApplicator(Item.Properties props)
|
||||
{
|
||||
super( AEConfig.instance().getColorApplicatorBattery(), props );
|
||||
addPropertyOverride(
|
||||
new ResourceLocation(AppEng.MOD_ID, "colored"),
|
||||
(itemStack, world, entity) -> {
|
||||
// If the stack has no color, don't use the colored model since the impact of calling getColor
|
||||
// for every quad is extremely high, if the stack tries to re-search its inventory for a new
|
||||
// paintball everytime
|
||||
AEColor col = getActiveColor( itemStack );
|
||||
return ( col != null ) ? 1 : 0;
|
||||
}
|
||||
);
|
||||
}
|
||||
@Override
|
||||
public ActionResultType onItemUse(ItemStack is, PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side,
|
||||
float hitX, float hitY, float hitZ) {
|
||||
final Block blk = w.getBlockState(pos).getBlock();
|
||||
|
||||
@Override
|
||||
public ActionResultType onItemUse( PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
return this.onItemUse( p.getHeldItem( hand ), p, w, pos, hand, side, hitX, hitY, hitZ );
|
||||
}
|
||||
ItemStack paintBall = this.getColor(is);
|
||||
|
||||
@Override
|
||||
public ActionResultType onItemUse( ItemStack is, PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
final Block blk = w.getBlockState( pos ).getBlock();
|
||||
final IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory(is, null,
|
||||
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
if (inv != null) {
|
||||
final IAEItemStack option = inv.extractItems(AEItemStack.fromItemStack(paintBall), Actionable.SIMULATE,
|
||||
new BaseActionSource());
|
||||
|
||||
ItemStack paintBall = this.getColor( is );
|
||||
if (option != null) {
|
||||
paintBall = option.createItemStack();
|
||||
paintBall.setCount(1);
|
||||
} else {
|
||||
paintBall = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
final IMEInventory<IAEItemStack> inv = AEApi.instance()
|
||||
.registries()
|
||||
.cell()
|
||||
.getCellInventory( is, null,
|
||||
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
if( inv != null )
|
||||
{
|
||||
final IAEItemStack option = inv.extractItems( AEItemStack.fromItemStack( paintBall ), Actionable.SIMULATE, new BaseActionSource() );
|
||||
if (!Platform.hasPermissions(new DimensionalCoord(w, pos), p)) {
|
||||
return ActionResultType.FAIL;
|
||||
}
|
||||
|
||||
if( option != null )
|
||||
{
|
||||
paintBall = option.createItemStack();
|
||||
paintBall.setCount( 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
paintBall = ItemStack.EMPTY;
|
||||
}
|
||||
final double powerPerUse = 100;
|
||||
if (!paintBall.isEmpty() && paintBall.getItem() instanceof SnowballItem) {
|
||||
final TileEntity te = w.getTileEntity(pos);
|
||||
// clean cables.
|
||||
if (te instanceof IColorableTile) {
|
||||
if (this.getAECurrentPower(is) > powerPerUse
|
||||
&& ((IColorableTile) te).getColor() != AEColor.TRANSPARENT) {
|
||||
if (((IColorableTile) te).recolourBlock(side, AEColor.TRANSPARENT, p)) {
|
||||
inv.extractItems(AEItemStack.fromItemStack(paintBall), Actionable.MODULATE,
|
||||
new BaseActionSource());
|
||||
this.extractAEPower(is, powerPerUse, Actionable.MODULATE);
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !Platform.hasPermissions( new DimensionalCoord( w, pos ), p ) )
|
||||
{
|
||||
return ActionResultType.FAIL;
|
||||
}
|
||||
// clean paint balls..
|
||||
final Block testBlk = w.getBlockState(pos.offset(side)).getBlock();
|
||||
final TileEntity painted = w.getTileEntity(pos.offset(side));
|
||||
if (this.getAECurrentPower(is) > powerPerUse && testBlk instanceof BlockPaint
|
||||
&& painted instanceof TilePaint) {
|
||||
inv.extractItems(AEItemStack.fromItemStack(paintBall), Actionable.MODULATE, new BaseActionSource());
|
||||
this.extractAEPower(is, powerPerUse, Actionable.MODULATE);
|
||||
((TilePaint) painted).cleanSide(side.getOpposite());
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
} else if (!paintBall.isEmpty()) {
|
||||
final AEColor color = this.getColorFromItem(paintBall);
|
||||
|
||||
final double powerPerUse = 100;
|
||||
if( !paintBall.isEmpty() && paintBall.getItem() instanceof SnowballItem )
|
||||
{
|
||||
final TileEntity te = w.getTileEntity( pos );
|
||||
// clean cables.
|
||||
if( te instanceof IColorableTile )
|
||||
{
|
||||
if( this.getAECurrentPower( is ) > powerPerUse && ( (IColorableTile) te ).getColor() != AEColor.TRANSPARENT )
|
||||
{
|
||||
if( ( (IColorableTile) te ).recolourBlock( side, AEColor.TRANSPARENT, p ) )
|
||||
{
|
||||
inv.extractItems( AEItemStack.fromItemStack( paintBall ), Actionable.MODULATE, new BaseActionSource() );
|
||||
this.extractAEPower( is, powerPerUse, Actionable.MODULATE );
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (color != null && this.getAECurrentPower(is) > powerPerUse) {
|
||||
if (color != AEColor.TRANSPARENT && this.recolourBlock(blk, side, w, pos, side, color, p)) {
|
||||
inv.extractItems(AEItemStack.fromItemStack(paintBall), Actionable.MODULATE,
|
||||
new BaseActionSource());
|
||||
this.extractAEPower(is, powerPerUse, Actionable.MODULATE);
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// clean paint balls..
|
||||
final Block testBlk = w.getBlockState( pos.offset( side ) ).getBlock();
|
||||
final TileEntity painted = w.getTileEntity( pos.offset( side ) );
|
||||
if( this.getAECurrentPower( is ) > powerPerUse && testBlk instanceof BlockPaint && painted instanceof TilePaint )
|
||||
{
|
||||
inv.extractItems( AEItemStack.fromItemStack( paintBall ), Actionable.MODULATE, new BaseActionSource() );
|
||||
this.extractAEPower( is, powerPerUse, Actionable.MODULATE );
|
||||
( (TilePaint) painted ).cleanSide( side.getOpposite() );
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
}
|
||||
else if( !paintBall.isEmpty() )
|
||||
{
|
||||
final AEColor color = this.getColorFromItem( paintBall );
|
||||
if (p.isCrouching()) {
|
||||
this.cycleColors(is, paintBall, 1);
|
||||
}
|
||||
|
||||
if( color != null && this.getAECurrentPower( is ) > powerPerUse )
|
||||
{
|
||||
if( color != AEColor.TRANSPARENT && this.recolourBlock( blk, side, w, pos, side, color, p ) )
|
||||
{
|
||||
inv.extractItems( AEItemStack.fromItemStack( paintBall ), Actionable.MODULATE, new BaseActionSource() );
|
||||
this.extractAEPower( is, powerPerUse, Actionable.MODULATE );
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActionResultType.FAIL;
|
||||
}
|
||||
|
||||
if( p.isCrouching() )
|
||||
{
|
||||
this.cycleColors( is, paintBall, 1 );
|
||||
}
|
||||
@Override
|
||||
public ITextComponent getDisplayName(final ItemStack is) {
|
||||
ITextComponent extra = GuiText.Empty.textComponent();
|
||||
|
||||
return ActionResultType.FAIL;
|
||||
}
|
||||
final AEColor selected = this.getActiveColor(is);
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName( final ItemStack is )
|
||||
{
|
||||
ITextComponent extra = GuiText.Empty.textComponent();
|
||||
if (selected != null && Platform.isClient()) {
|
||||
extra = new TranslationTextComponent(selected.translationKey);
|
||||
}
|
||||
|
||||
final AEColor selected = this.getActiveColor( is );
|
||||
return super.getDisplayName(is).appendText(" - ").appendSibling(extra);
|
||||
}
|
||||
|
||||
if( selected != null && Platform.isClient() )
|
||||
{
|
||||
extra = new TranslationTextComponent(selected.translationKey);
|
||||
}
|
||||
public AEColor getActiveColor(final ItemStack tol) {
|
||||
return this.getColorFromItem(this.getColor(tol));
|
||||
}
|
||||
|
||||
return super.getDisplayName( is ).appendText(" - ").appendSibling( extra );
|
||||
}
|
||||
private AEColor getColorFromItem(final ItemStack paintBall) {
|
||||
if (paintBall.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public AEColor getActiveColor( final ItemStack tol )
|
||||
{
|
||||
return this.getColorFromItem( this.getColor( tol ) );
|
||||
}
|
||||
if (paintBall.getItem() instanceof SnowballItem) {
|
||||
return AEColor.TRANSPARENT;
|
||||
}
|
||||
|
||||
private AEColor getColorFromItem( final ItemStack paintBall )
|
||||
{
|
||||
if( paintBall.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if( paintBall.getItem() instanceof SnowballItem )
|
||||
{
|
||||
return AEColor.TRANSPARENT;
|
||||
}
|
||||
|
||||
if( paintBall.getItem() instanceof ItemPaintBall )
|
||||
{
|
||||
final ItemPaintBall ipb = (ItemPaintBall) paintBall.getItem();
|
||||
return ipb.getColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME final int[] id = OreDictionary.getOreIDs( paintBall );
|
||||
if (paintBall.getItem() instanceof ItemPaintBall) {
|
||||
final ItemPaintBall ipb = (ItemPaintBall) paintBall.getItem();
|
||||
return ipb.getColor();
|
||||
} else {
|
||||
// FIXME final int[] id = OreDictionary.getOreIDs( paintBall );
|
||||
// FIXME
|
||||
// FIXME for( final int oreID : id )
|
||||
// FIXME {
|
||||
// FIXME if( ORE_TO_COLOR.containsKey( oreID ) )
|
||||
// FIXME {
|
||||
// FIXME return ORE_TO_COLOR.get( oreID );
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
}
|
||||
// FIXME for( final int oreID : id )
|
||||
// FIXME {
|
||||
// FIXME if( ORE_TO_COLOR.containsKey( oreID ) )
|
||||
// FIXME {
|
||||
// FIXME return ORE_TO_COLOR.get( oreID );
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack getColor( final ItemStack is )
|
||||
{
|
||||
final CompoundNBT c = is.getTag();
|
||||
if( c != null && c.contains(TAG_COLOR) )
|
||||
{
|
||||
final CompoundNBT color = c.getCompound( TAG_COLOR );
|
||||
final ItemStack oldColor = ItemStack.read(color);
|
||||
if( !oldColor.isEmpty() )
|
||||
{
|
||||
return oldColor;
|
||||
}
|
||||
}
|
||||
public ItemStack getColor(final ItemStack is) {
|
||||
final CompoundNBT c = is.getTag();
|
||||
if (c != null && c.contains(TAG_COLOR)) {
|
||||
final CompoundNBT color = c.getCompound(TAG_COLOR);
|
||||
final ItemStack oldColor = ItemStack.read(color);
|
||||
if (!oldColor.isEmpty()) {
|
||||
return oldColor;
|
||||
}
|
||||
}
|
||||
|
||||
return this.findNextColor( is, ItemStack.EMPTY, 0 );
|
||||
}
|
||||
return this.findNextColor(is, ItemStack.EMPTY, 0);
|
||||
}
|
||||
|
||||
private ItemStack findNextColor( final ItemStack is, final ItemStack anchor, final int scrollOffset )
|
||||
{
|
||||
ItemStack newColor = ItemStack.EMPTY;
|
||||
private ItemStack findNextColor(final ItemStack is, final ItemStack anchor, final int scrollOffset) {
|
||||
ItemStack newColor = ItemStack.EMPTY;
|
||||
|
||||
final IMEInventory<IAEItemStack> inv = AEApi.instance()
|
||||
.registries()
|
||||
.cell()
|
||||
.getCellInventory( is, null,
|
||||
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
if( inv != null )
|
||||
{
|
||||
final IItemList<IAEItemStack> itemList = inv
|
||||
.getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
|
||||
if( anchor.isEmpty() )
|
||||
{
|
||||
final IAEItemStack firstItem = itemList.getFirstItem();
|
||||
if( firstItem != null )
|
||||
{
|
||||
newColor = firstItem.asItemStackRepresentation();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final LinkedList<IAEItemStack> list = new LinkedList<>();
|
||||
final IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory(is, null,
|
||||
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
if (inv != null) {
|
||||
final IItemList<IAEItemStack> itemList = inv.getAvailableItems(
|
||||
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList());
|
||||
if (anchor.isEmpty()) {
|
||||
final IAEItemStack firstItem = itemList.getFirstItem();
|
||||
if (firstItem != null) {
|
||||
newColor = firstItem.asItemStackRepresentation();
|
||||
}
|
||||
} else {
|
||||
final LinkedList<IAEItemStack> list = new LinkedList<>();
|
||||
|
||||
for( final IAEItemStack i : itemList )
|
||||
{
|
||||
list.add( i );
|
||||
}
|
||||
for (final IAEItemStack i : itemList) {
|
||||
list.add(i);
|
||||
}
|
||||
|
||||
Collections.sort( list, ( a, b ) -> Integer.compare( a.getItemDamage(), b.getItemDamage() ) );
|
||||
Collections.sort(list, (a, b) -> Integer.compare(a.getItemDamage(), b.getItemDamage()));
|
||||
|
||||
if( list.size() <= 0 )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if (list.size() <= 0) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
IAEItemStack where = list.getFirst();
|
||||
int cycles = 1 + list.size();
|
||||
IAEItemStack where = list.getFirst();
|
||||
int cycles = 1 + list.size();
|
||||
|
||||
while( cycles > 0 && !where.equals( anchor ) )
|
||||
{
|
||||
list.addLast( list.removeFirst() );
|
||||
cycles--;
|
||||
where = list.getFirst();
|
||||
}
|
||||
while (cycles > 0 && !where.equals(anchor)) {
|
||||
list.addLast(list.removeFirst());
|
||||
cycles--;
|
||||
where = list.getFirst();
|
||||
}
|
||||
|
||||
if( scrollOffset > 0 )
|
||||
{
|
||||
list.addLast( list.removeFirst() );
|
||||
}
|
||||
if (scrollOffset > 0) {
|
||||
list.addLast(list.removeFirst());
|
||||
}
|
||||
|
||||
if( scrollOffset < 0 )
|
||||
{
|
||||
list.addFirst( list.removeLast() );
|
||||
}
|
||||
if (scrollOffset < 0) {
|
||||
list.addFirst(list.removeLast());
|
||||
}
|
||||
|
||||
return list.get( 0 ).asItemStackRepresentation();
|
||||
}
|
||||
}
|
||||
return list.get(0).asItemStackRepresentation();
|
||||
}
|
||||
}
|
||||
|
||||
if( !newColor.isEmpty() )
|
||||
{
|
||||
this.setColor( is, newColor );
|
||||
}
|
||||
if (!newColor.isEmpty()) {
|
||||
this.setColor(is, newColor);
|
||||
}
|
||||
|
||||
return newColor;
|
||||
}
|
||||
return newColor;
|
||||
}
|
||||
|
||||
private void setColor( final ItemStack is, final ItemStack newColor )
|
||||
{
|
||||
private void setColor(final ItemStack is, final ItemStack newColor) {
|
||||
final CompoundNBT data = is.getOrCreateTag();
|
||||
if( newColor.isEmpty() )
|
||||
{
|
||||
data.remove( TAG_COLOR );
|
||||
}
|
||||
else
|
||||
{
|
||||
final CompoundNBT color = new CompoundNBT();
|
||||
newColor.write(color);
|
||||
data.put( TAG_COLOR, color );
|
||||
}
|
||||
}
|
||||
if (newColor.isEmpty()) {
|
||||
data.remove(TAG_COLOR);
|
||||
} else {
|
||||
final CompoundNBT color = new CompoundNBT();
|
||||
newColor.write(color);
|
||||
data.put(TAG_COLOR, color);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean recolourBlock( final Block blk, final Direction side, final World w, final BlockPos pos, final Direction orientation, final AEColor newColor, final PlayerEntity p )
|
||||
{
|
||||
final BlockState state = w.getBlockState( pos );
|
||||
private boolean recolourBlock(final Block blk, final Direction side, final World w, final BlockPos pos,
|
||||
final Direction orientation, final AEColor newColor, final PlayerEntity p) {
|
||||
final BlockState state = w.getBlockState(pos);
|
||||
|
||||
// FIXME if( blk instanceof BlockColored )
|
||||
// FIXME {
|
||||
@@ -405,156 +357,129 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
|
||||
// return w.setBlockState( pos, Blocks.STAINED_HARDENED_CLAY.getDefaultState().with( BlockColored.COLOR, newColor.dye ) );
|
||||
// }
|
||||
|
||||
if( blk instanceof BlockCableBus )
|
||||
{
|
||||
return ( (BlockCableBus) blk ).recolorBlock( w, pos, side, newColor.dye, p );
|
||||
}
|
||||
if (blk instanceof BlockCableBus) {
|
||||
return ((BlockCableBus) blk).recolorBlock(w, pos, side, newColor.dye, p);
|
||||
}
|
||||
|
||||
return blk.recolorBlock( state, w, pos, side, newColor.dye );
|
||||
}
|
||||
return blk.recolorBlock(state, w, pos, side, newColor.dye);
|
||||
}
|
||||
|
||||
public void cycleColors( final ItemStack is, final ItemStack paintBall, final int i )
|
||||
{
|
||||
if( paintBall.isEmpty() )
|
||||
{
|
||||
this.setColor( is, this.getColor( is ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setColor( is, this.findNextColor( is, paintBall, i ) );
|
||||
}
|
||||
}
|
||||
public void cycleColors(final ItemStack is, final ItemStack paintBall, final int i) {
|
||||
if (paintBall.isEmpty()) {
|
||||
this.setColor(is, this.getColor(is));
|
||||
} else {
|
||||
this.setColor(is, this.findNextColor(is, paintBall, i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
|
||||
{
|
||||
super.addInformation( stack, world, lines, advancedTooltips );
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines,
|
||||
final ITooltipFlag advancedTooltips) {
|
||||
super.addInformation(stack, world, lines, advancedTooltips);
|
||||
|
||||
final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance()
|
||||
.registries()
|
||||
.cell()
|
||||
.getCellInventory( stack, null,
|
||||
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory(stack,
|
||||
null, AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
|
||||
AEApi.instance().client().addCellInformation( cdi, lines );
|
||||
}
|
||||
AEApi.instance().client().addCellInformation(cdi, lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytes( final ItemStack cellItem )
|
||||
{
|
||||
return 512;
|
||||
}
|
||||
@Override
|
||||
public int getBytes(final ItemStack cellItem) {
|
||||
return 512;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytesPerType( final ItemStack cellItem )
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
@Override
|
||||
public int getBytesPerType(final ItemStack cellItem) {
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalTypes( final ItemStack cellItem )
|
||||
{
|
||||
return 27;
|
||||
}
|
||||
@Override
|
||||
public int getTotalTypes(final ItemStack cellItem) {
|
||||
return 27;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlackListed( final ItemStack cellItem, final IAEItemStack requestedAddition )
|
||||
{
|
||||
if( requestedAddition != null )
|
||||
{
|
||||
// FIXME final int[] id = OreDictionary.getOreIDs( requestedAddition.getDefinition() );
|
||||
@Override
|
||||
public boolean isBlackListed(final ItemStack cellItem, final IAEItemStack requestedAddition) {
|
||||
if (requestedAddition != null) {
|
||||
// FIXME final int[] id = OreDictionary.getOreIDs(
|
||||
// requestedAddition.getDefinition() );
|
||||
|
||||
// FIXME for( final int x : id )
|
||||
// FIXME {
|
||||
// FIXME if( ORE_TO_COLOR.containsKey( x ) )
|
||||
// FIXME {
|
||||
// FIXME return false;
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
// FIXME for( final int x : id )
|
||||
// FIXME {
|
||||
// FIXME if( ORE_TO_COLOR.containsKey( x ) )
|
||||
// FIXME {
|
||||
// FIXME return false;
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
|
||||
if( requestedAddition.getItem() instanceof SnowballItem )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (requestedAddition.getItem() instanceof SnowballItem) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !( requestedAddition.getItem() instanceof ItemPaintBall && requestedAddition.getItemDamage() < 20 );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return !(requestedAddition.getItem() instanceof ItemPaintBall && requestedAddition.getItemDamage() < 20);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storableInStorageCell()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean storableInStorageCell() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageCell( final ItemStack i )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isStorageCell(final ItemStack i) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain()
|
||||
{
|
||||
return 0.5;
|
||||
}
|
||||
@Override
|
||||
public double getIdleDrain() {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedGroupName( final Set<ItemStack> others, final ItemStack is )
|
||||
{
|
||||
return GuiText.StorageCells.getTranslationKey();
|
||||
}
|
||||
@Override
|
||||
public String getUnlocalizedGroupName(final Set<ItemStack> others, final ItemStack is) {
|
||||
return GuiText.StorageCells.getTranslationKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable( final ItemStack is )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isEditable(final ItemStack is) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getUpgradesInventory( final ItemStack is )
|
||||
{
|
||||
return new CellUpgrades( is, 2 );
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getUpgradesInventory(final ItemStack is) {
|
||||
return new CellUpgrades(is, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getConfigInventory( final ItemStack is )
|
||||
{
|
||||
return new CellConfig( is );
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getConfigInventory(final ItemStack is) {
|
||||
return new CellConfig(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode( final ItemStack is )
|
||||
{
|
||||
final String fz = is.getOrCreateTag().getString( "FuzzyMode" );
|
||||
try
|
||||
{
|
||||
return FuzzyMode.valueOf( fz );
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode(final ItemStack is) {
|
||||
final String fz = is.getOrCreateTag().getString("FuzzyMode");
|
||||
try {
|
||||
return FuzzyMode.valueOf(fz);
|
||||
} catch (final Throwable t) {
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuzzyMode( final ItemStack is, final FuzzyMode fzMode )
|
||||
{
|
||||
@Override
|
||||
public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
|
||||
is.getOrCreateTag().putString("FuzzyMode", fzMode.name());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWheel( final ItemStack is, final boolean up )
|
||||
{
|
||||
this.cycleColors( is, this.getColor( is ), up ? 1 : -1 );
|
||||
}
|
||||
@Override
|
||||
public void onWheel(final ItemStack is, final boolean up) {
|
||||
this.cycleColors(is, this.getColor(is), up ? 1 : -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package appeng.items.tools.powered;
|
||||
|
||||
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -12,56 +11,52 @@ import appeng.bootstrap.IItemRendering;
|
||||
import appeng.bootstrap.ItemRenderingCustomizer;
|
||||
import appeng.core.AppEng;
|
||||
|
||||
public class ToolColorApplicatorRendering extends ItemRenderingCustomizer {
|
||||
|
||||
public class ToolColorApplicatorRendering extends ItemRenderingCustomizer
|
||||
{
|
||||
private static final ModelResourceLocation MODEL_COLORED = new ModelResourceLocation(
|
||||
new ResourceLocation(AppEng.MOD_ID, "builtin/color_applicator_colored"), "inventory");
|
||||
private static final ModelResourceLocation MODEL_UNCOLORED = new ModelResourceLocation(
|
||||
new ResourceLocation(AppEng.MOD_ID, "color_applicator_uncolored"), "inventory");
|
||||
|
||||
private static final ModelResourceLocation MODEL_COLORED = new ModelResourceLocation( new ResourceLocation( AppEng.MOD_ID, "builtin/color_applicator_colored" ), "inventory" );
|
||||
private static final ModelResourceLocation MODEL_UNCOLORED = new ModelResourceLocation( new ResourceLocation( AppEng.MOD_ID, "color_applicator_uncolored" ), "inventory" );
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void customize(IItemRendering rendering) {
|
||||
// FIXME rendering.builtInModel( "models/item/builtin/color_applicator_colored",
|
||||
// new ColorApplicatorModel() );
|
||||
rendering.variants(MODEL_COLORED, MODEL_UNCOLORED);
|
||||
rendering.color(this::getColor);
|
||||
// FIXME rendering.meshDefinition( this::getMesh );
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public void customize( IItemRendering rendering )
|
||||
{
|
||||
// FIXME rendering.builtInModel( "models/item/builtin/color_applicator_colored", new ColorApplicatorModel() );
|
||||
rendering.variants( MODEL_COLORED, MODEL_UNCOLORED );
|
||||
rendering.color( this::getColor );
|
||||
// FIXME rendering.meshDefinition( this::getMesh );
|
||||
}
|
||||
private ModelResourceLocation getMesh(ItemStack itemStack) {
|
||||
// If the stack has no color, don't use the colored model since the impact of
|
||||
// calling getColor for every quad is
|
||||
// extremely high,
|
||||
// if the stack tries to re-search its inventory for a new paintball everytime
|
||||
AEColor col = ((ToolColorApplicator) itemStack.getItem()).getActiveColor(itemStack);
|
||||
return (col != null) ? MODEL_COLORED : MODEL_UNCOLORED;
|
||||
}
|
||||
|
||||
private ModelResourceLocation getMesh( ItemStack itemStack )
|
||||
{
|
||||
// If the stack has no color, don't use the colored model since the impact of calling getColor for every quad is
|
||||
// extremely high,
|
||||
// if the stack tries to re-search its inventory for a new paintball everytime
|
||||
AEColor col = ( (ToolColorApplicator) itemStack.getItem() ).getActiveColor( itemStack );
|
||||
return ( col != null ) ? MODEL_COLORED : MODEL_UNCOLORED;
|
||||
}
|
||||
private int getColor(ItemStack itemStack, int idx) {
|
||||
if (idx == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int getColor( ItemStack itemStack, int idx )
|
||||
{
|
||||
if( idx == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
final AEColor col = ((ToolColorApplicator) itemStack.getItem()).getActiveColor(itemStack);
|
||||
|
||||
final AEColor col = ( (ToolColorApplicator) itemStack.getItem() ).getActiveColor( itemStack );
|
||||
if (col == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( col == null )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch( idx )
|
||||
{
|
||||
case 1:
|
||||
return col.blackVariant;
|
||||
case 2:
|
||||
return col.mediumVariant;
|
||||
case 3:
|
||||
return col.whiteVariant;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
switch (idx) {
|
||||
case 1:
|
||||
return col.blackVariant;
|
||||
case 2:
|
||||
return col.mediumVariant;
|
||||
case 3:
|
||||
return col.whiteVariant;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.items.tools.powered;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -55,246 +54,206 @@ import appeng.items.tools.powered.powersink.AEBasePoweredItem;
|
||||
import appeng.util.InWorldToolOperationResult;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockTool {
|
||||
private final Map<InWorldToolOperationIngredient, InWorldToolOperationResult> heatUp;
|
||||
private final Map<InWorldToolOperationIngredient, InWorldToolOperationResult> coolDown;
|
||||
|
||||
public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockTool
|
||||
{
|
||||
private final Map<InWorldToolOperationIngredient, InWorldToolOperationResult> heatUp;
|
||||
private final Map<InWorldToolOperationIngredient, InWorldToolOperationResult> coolDown;
|
||||
public ToolEntropyManipulator(Item.Properties props) {
|
||||
super(AEConfig.instance().getEntropyManipulatorBattery(), props);
|
||||
|
||||
public ToolEntropyManipulator(Item.Properties props)
|
||||
{
|
||||
super( AEConfig.instance().getEntropyManipulatorBattery(), props );
|
||||
this.heatUp = new HashMap<>();
|
||||
this.coolDown = new HashMap<>();
|
||||
|
||||
this.heatUp = new HashMap<>();
|
||||
this.coolDown = new HashMap<>();
|
||||
|
||||
this.coolDown.put( new InWorldToolOperationIngredient( Blocks.STONE.getDefaultState() ),
|
||||
new InWorldToolOperationResult( Blocks.COBBLESTONE.getDefaultState() ) );
|
||||
this.coolDown.put(new InWorldToolOperationIngredient(Blocks.STONE.getDefaultState()),
|
||||
new InWorldToolOperationResult(Blocks.COBBLESTONE.getDefaultState()));
|
||||
// FIXME this.coolDown.put( new InWorldToolOperationIngredient( Blocks.STONE_BRICKS.getDefaultState() ),
|
||||
// FIXME new InWorldToolOperationResult( Blocks.STONE_BRICKS.getStateFromMeta( 2 ) ) );
|
||||
this.coolDown.put( new InWorldToolOperationIngredient( Blocks.LAVA, true ), new InWorldToolOperationResult( Blocks.OBSIDIAN.getDefaultState() ) );
|
||||
this.coolDown.put(new InWorldToolOperationIngredient(Blocks.LAVA, true),
|
||||
new InWorldToolOperationResult(Blocks.OBSIDIAN.getDefaultState()));
|
||||
// FIXME this.coolDown.put( new InWorldToolOperationIngredient( Blocks.FLOWING_LAVA, true ),
|
||||
// FIXME new InWorldToolOperationResult( Blocks.OBSIDIAN.getDefaultState() ) );
|
||||
this.coolDown.put( new InWorldToolOperationIngredient( Blocks.GRASS, true ), new InWorldToolOperationResult( Blocks.DIRT.getDefaultState() ) );
|
||||
this.coolDown.put(new InWorldToolOperationIngredient(Blocks.GRASS, true),
|
||||
new InWorldToolOperationResult(Blocks.DIRT.getDefaultState()));
|
||||
|
||||
final List<ItemStack> snowBalls = new ArrayList<>();
|
||||
snowBalls.add( new ItemStack( Items.SNOWBALL ) );
|
||||
final List<ItemStack> snowBalls = new ArrayList<>();
|
||||
snowBalls.add(new ItemStack(Items.SNOWBALL));
|
||||
// FIXME this.coolDown.put( new InWorldToolOperationIngredient( Blocks.FLOWING_WATER, true ), new InWorldToolOperationResult( null, snowBalls ) );
|
||||
this.coolDown.put( new InWorldToolOperationIngredient( Blocks.WATER, true ), new InWorldToolOperationResult( Blocks.ICE.getDefaultState() ) );
|
||||
this.coolDown.put(new InWorldToolOperationIngredient(Blocks.WATER, true),
|
||||
new InWorldToolOperationResult(Blocks.ICE.getDefaultState()));
|
||||
|
||||
this.heatUp.put( new InWorldToolOperationIngredient( Blocks.ICE.getDefaultState() ), new InWorldToolOperationResult( Blocks.WATER.getDefaultState() ) );
|
||||
this.heatUp.put(new InWorldToolOperationIngredient(Blocks.ICE.getDefaultState()),
|
||||
new InWorldToolOperationResult(Blocks.WATER.getDefaultState()));
|
||||
// FIXME this.heatUp.put( new InWorldToolOperationIngredient( Blocks.FLOWING_WATER, true ), new InWorldToolOperationResult() );
|
||||
this.heatUp.put( new InWorldToolOperationIngredient( Blocks.WATER, true ), new InWorldToolOperationResult() );
|
||||
this.heatUp.put(new InWorldToolOperationIngredient(Blocks.WATER, true), new InWorldToolOperationResult());
|
||||
// FIXME this.heatUp.put( new InWorldToolOperationIngredient( Blocks.SNOW, true ),
|
||||
// FIXME new InWorldToolOperationResult( Blocks.FLOWING_WATER.getStateFromMeta( 7 ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
private static class InWorldToolOperationIngredient
|
||||
{
|
||||
private final BlockState state;
|
||||
private final boolean blockOnly;
|
||||
private static class InWorldToolOperationIngredient {
|
||||
private final BlockState state;
|
||||
private final boolean blockOnly;
|
||||
|
||||
public InWorldToolOperationIngredient( final BlockState state )
|
||||
{
|
||||
this.state = state;
|
||||
this.blockOnly = false;
|
||||
}
|
||||
public InWorldToolOperationIngredient(final BlockState state) {
|
||||
this.state = state;
|
||||
this.blockOnly = false;
|
||||
}
|
||||
|
||||
public InWorldToolOperationIngredient( final Block blk, final boolean b )
|
||||
{
|
||||
this.state = blk.getDefaultState();
|
||||
this.blockOnly = b;
|
||||
}
|
||||
public InWorldToolOperationIngredient(final Block blk, final boolean b) {
|
||||
this.state = blk.getDefaultState();
|
||||
this.blockOnly = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.state.getBlock().hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.state.getBlock().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( final Object obj )
|
||||
{
|
||||
if( obj == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( this.getClass() != obj.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
final InWorldToolOperationIngredient other = (InWorldToolOperationIngredient) obj;
|
||||
return this.state == other.state && ( this.blockOnly && this.state.getBlock() == other.state.getBlock() );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (this.getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final InWorldToolOperationIngredient other = (InWorldToolOperationIngredient) obj;
|
||||
return this.state == other.state && (this.blockOnly && this.state.getBlock() == other.state.getBlock());
|
||||
}
|
||||
}
|
||||
|
||||
private void heat( final BlockState state, final World w, final BlockPos pos )
|
||||
{
|
||||
InWorldToolOperationResult r = this.heatUp.get( new InWorldToolOperationIngredient( state ) );
|
||||
private void heat(final BlockState state, final World w, final BlockPos pos) {
|
||||
InWorldToolOperationResult r = this.heatUp.get(new InWorldToolOperationIngredient(state));
|
||||
|
||||
if( r == null )
|
||||
{
|
||||
r = this.heatUp.get( new InWorldToolOperationIngredient( state.getBlock(), true ) );
|
||||
}
|
||||
if (r == null) {
|
||||
r = this.heatUp.get(new InWorldToolOperationIngredient(state.getBlock(), true));
|
||||
}
|
||||
|
||||
if( r.getBlockState() != null )
|
||||
{
|
||||
w.setBlockState( pos, r.getBlockState(), 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
w.removeBlock(pos, false);
|
||||
}
|
||||
if (r.getBlockState() != null) {
|
||||
w.setBlockState(pos, r.getBlockState(), 3);
|
||||
} else {
|
||||
w.removeBlock(pos, false);
|
||||
}
|
||||
|
||||
if( r.getDrops() != null )
|
||||
{
|
||||
Platform.spawnDrops( w, pos, r.getDrops() );
|
||||
}
|
||||
}
|
||||
if (r.getDrops() != null) {
|
||||
Platform.spawnDrops(w, pos, r.getDrops());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canHeat( final BlockState state )
|
||||
{
|
||||
InWorldToolOperationResult r = this.heatUp.get( new InWorldToolOperationIngredient( state ) );
|
||||
private boolean canHeat(final BlockState state) {
|
||||
InWorldToolOperationResult r = this.heatUp.get(new InWorldToolOperationIngredient(state));
|
||||
|
||||
if( r == null )
|
||||
{
|
||||
r = this.heatUp.get( new InWorldToolOperationIngredient( state.getBlock(), true ) );
|
||||
}
|
||||
if (r == null) {
|
||||
r = this.heatUp.get(new InWorldToolOperationIngredient(state.getBlock(), true));
|
||||
}
|
||||
|
||||
return r != null;
|
||||
}
|
||||
return r != null;
|
||||
}
|
||||
|
||||
private void cool( final BlockState state, final World w, final BlockPos pos )
|
||||
{
|
||||
InWorldToolOperationResult r = this.coolDown.get( new InWorldToolOperationIngredient( state ) );
|
||||
private void cool(final BlockState state, final World w, final BlockPos pos) {
|
||||
InWorldToolOperationResult r = this.coolDown.get(new InWorldToolOperationIngredient(state));
|
||||
|
||||
if( r == null )
|
||||
{
|
||||
r = this.coolDown.get( new InWorldToolOperationIngredient( state.getBlock(), true ) );
|
||||
}
|
||||
if (r == null) {
|
||||
r = this.coolDown.get(new InWorldToolOperationIngredient(state.getBlock(), true));
|
||||
}
|
||||
|
||||
if( r.getBlockState() != null )
|
||||
{
|
||||
w.setBlockState( pos, r.getBlockState(), 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
w.removeBlock(pos, false);
|
||||
}
|
||||
if (r.getBlockState() != null) {
|
||||
w.setBlockState(pos, r.getBlockState(), 3);
|
||||
} else {
|
||||
w.removeBlock(pos, false);
|
||||
}
|
||||
|
||||
if( r.getDrops() != null )
|
||||
{
|
||||
Platform.spawnDrops( w, pos, r.getDrops() );
|
||||
}
|
||||
}
|
||||
if (r.getDrops() != null) {
|
||||
Platform.spawnDrops(w, pos, r.getDrops());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canCool( final BlockState state )
|
||||
{
|
||||
InWorldToolOperationResult r = this.coolDown.get( new InWorldToolOperationIngredient( state ) );
|
||||
private boolean canCool(final BlockState state) {
|
||||
InWorldToolOperationResult r = this.coolDown.get(new InWorldToolOperationIngredient(state));
|
||||
|
||||
if( r == null )
|
||||
{
|
||||
r = this.coolDown.get( new InWorldToolOperationIngredient( state.getBlock(), true ) );
|
||||
}
|
||||
if (r == null) {
|
||||
r = this.coolDown.get(new InWorldToolOperationIngredient(state.getBlock(), true));
|
||||
}
|
||||
|
||||
return r != null;
|
||||
}
|
||||
return r != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hitEntity( final ItemStack item, final LivingEntity target, final LivingEntity hitter )
|
||||
{
|
||||
if( this.getAECurrentPower( item ) > 1600 )
|
||||
{
|
||||
this.extractAEPower( item, 1600, Actionable.MODULATE );
|
||||
target.setFire( 8 );
|
||||
}
|
||||
@Override
|
||||
public boolean hitEntity(final ItemStack item, final LivingEntity target, final LivingEntity hitter) {
|
||||
if (this.getAECurrentPower(item) > 1600) {
|
||||
this.extractAEPower(item, 1600, Actionable.MODULATE);
|
||||
target.setFire(8);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick( final World w, final PlayerEntity p, final Hand hand )
|
||||
{
|
||||
final RayTraceResult target = this.rayTrace( w, p, RayTraceContext.FluidMode.ANY );
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(final World w, final PlayerEntity p, final Hand hand) {
|
||||
final RayTraceResult target = this.rayTrace(w, p, RayTraceContext.FluidMode.ANY);
|
||||
|
||||
if( target.getType() != RayTraceResult.Type.BLOCK )
|
||||
{
|
||||
return new ActionResult<>( ActionResultType.FAIL, p.getHeldItem( hand ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
BlockPos pos = ((BlockRayTraceResult) target).getPos();
|
||||
final BlockState state = w.getBlockState( pos );
|
||||
if( state.getMaterial() == Material.LAVA || state.getMaterial() == Material.WATER )
|
||||
{
|
||||
if( Platform.hasPermissions( new DimensionalCoord( w, pos ), p ) )
|
||||
{
|
||||
this.onItemUse( p, w, pos, hand, Direction.UP, 0.0F, 0.0F, 0.0F );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (target.getType() != RayTraceResult.Type.BLOCK) {
|
||||
return new ActionResult<>(ActionResultType.FAIL, p.getHeldItem(hand));
|
||||
} else {
|
||||
BlockPos pos = ((BlockRayTraceResult) target).getPos();
|
||||
final BlockState state = w.getBlockState(pos);
|
||||
if (state.getMaterial() == Material.LAVA || state.getMaterial() == Material.WATER) {
|
||||
if (Platform.hasPermissions(new DimensionalCoord(w, pos), p)) {
|
||||
this.onItemUse(p, w, pos, hand, Direction.UP, 0.0F, 0.0F, 0.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ActionResult<>( ActionResultType.SUCCESS, p.getHeldItem( hand ) );
|
||||
}
|
||||
return new ActionResult<>(ActionResultType.SUCCESS, p.getHeldItem(hand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onItemUse( PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
return this.onItemUse( p.getHeldItem( hand ), p, w, pos, hand, side, hitX, hitY, hitZ );
|
||||
}
|
||||
@Override
|
||||
public ActionResultType onItemUse(PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side, float hitX,
|
||||
float hitY, float hitZ) {
|
||||
return this.onItemUse(p.getHeldItem(hand), p, w, pos, hand, side, hitX, hitY, hitZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onItemUse( ItemStack item, PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
if( this.getAECurrentPower( item ) > 1600 )
|
||||
{
|
||||
if( !p.canPlayerEdit( pos, side, item ) )
|
||||
{
|
||||
return ActionResultType.FAIL;
|
||||
}
|
||||
@Override
|
||||
public ActionResultType onItemUse(ItemStack item, PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side,
|
||||
float hitX, float hitY, float hitZ) {
|
||||
if (this.getAECurrentPower(item) > 1600) {
|
||||
if (!p.canPlayerEdit(pos, side, item)) {
|
||||
return ActionResultType.FAIL;
|
||||
}
|
||||
|
||||
final BlockState state = w.getBlockState( pos );
|
||||
final Block blockID = state.getBlock();
|
||||
final BlockState state = w.getBlockState(pos);
|
||||
final Block blockID = state.getBlock();
|
||||
|
||||
if( p.isCrouching() )
|
||||
{
|
||||
if( this.canCool( state ) )
|
||||
{
|
||||
this.extractAEPower( item, 1600, Actionable.MODULATE );
|
||||
this.cool( state, w, pos );
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( blockID instanceof TNTBlock)
|
||||
{
|
||||
w.removeBlock(pos, false);
|
||||
( (TNTBlock) blockID ).explode( w, pos );
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
if (p.isCrouching()) {
|
||||
if (this.canCool(state)) {
|
||||
this.extractAEPower(item, 1600, Actionable.MODULATE);
|
||||
this.cool(state, w, pos);
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
} else {
|
||||
if (blockID instanceof TNTBlock) {
|
||||
w.removeBlock(pos, false);
|
||||
((TNTBlock) blockID).explode(w, pos);
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
if( blockID instanceof BlockTinyTNT )
|
||||
{
|
||||
w.removeBlock(pos, false);
|
||||
( (BlockTinyTNT) blockID ).startFuse( w, pos, p );
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
if (blockID instanceof BlockTinyTNT) {
|
||||
w.removeBlock(pos, false);
|
||||
((BlockTinyTNT) blockID).startFuse(w, pos, p);
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
if( this.canHeat( state ) )
|
||||
{
|
||||
this.extractAEPower( item, 1600, Actionable.MODULATE );
|
||||
this.heat( state, w, pos );
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
if (this.canHeat(state)) {
|
||||
this.extractAEPower(item, 1600, Actionable.MODULATE);
|
||||
this.heat(state, w, pos);
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
final ItemStack[] stack = Platform.getBlockDrops( w, pos );
|
||||
final List<ItemStack> out = new ArrayList<>();
|
||||
boolean hasFurnaceable = false;
|
||||
boolean canFurnaceable = true;
|
||||
final ItemStack[] stack = Platform.getBlockDrops(w, pos);
|
||||
final List<ItemStack> out = new ArrayList<>();
|
||||
boolean hasFurnaceable = false;
|
||||
boolean canFurnaceable = true;
|
||||
|
||||
for( final ItemStack i : stack )
|
||||
{
|
||||
for (final ItemStack i : stack) {
|
||||
// FIXME final ItemStack result = FurnaceRecipes.instance().getSmeltingResult( i );
|
||||
// FIXME
|
||||
// FIXME if( !result.isEmpty() )
|
||||
@@ -315,53 +274,47 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
|
||||
// FIXME canFurnaceable = false;
|
||||
// FIXME out.add( i );
|
||||
// FIXME }
|
||||
}
|
||||
}
|
||||
|
||||
if( hasFurnaceable && canFurnaceable )
|
||||
{
|
||||
this.extractAEPower( item, 1600, Actionable.MODULATE );
|
||||
final InWorldToolOperationResult or = InWorldToolOperationResult.getBlockOperationResult( out.toArray( new ItemStack[out.size()] ) );
|
||||
w.playSound( p, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.PLAYERS, 1.0F,
|
||||
random.nextFloat() * 0.4F + 0.8F );
|
||||
if (hasFurnaceable && canFurnaceable) {
|
||||
this.extractAEPower(item, 1600, Actionable.MODULATE);
|
||||
final InWorldToolOperationResult or = InWorldToolOperationResult
|
||||
.getBlockOperationResult(out.toArray(new ItemStack[out.size()]));
|
||||
w.playSound(p, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D,
|
||||
SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.PLAYERS, 1.0F,
|
||||
random.nextFloat() * 0.4F + 0.8F);
|
||||
|
||||
if( or.getBlockState() == null )
|
||||
{
|
||||
w.setBlockState( pos, Platform.AIR_BLOCK.getDefaultState(), 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
w.setBlockState( pos, or.getBlockState(), 3 );
|
||||
}
|
||||
if (or.getBlockState() == null) {
|
||||
w.setBlockState(pos, Platform.AIR_BLOCK.getDefaultState(), 3);
|
||||
} else {
|
||||
w.setBlockState(pos, or.getBlockState(), 3);
|
||||
}
|
||||
|
||||
if( or.getDrops() != null )
|
||||
{
|
||||
Platform.spawnDrops( w, pos, or.getDrops() );
|
||||
}
|
||||
if (or.getDrops() != null) {
|
||||
Platform.spawnDrops(w, pos, or.getDrops());
|
||||
}
|
||||
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
final BlockPos offsetPos = pos.offset( side );
|
||||
return ActionResultType.SUCCESS;
|
||||
} else {
|
||||
final BlockPos offsetPos = pos.offset(side);
|
||||
|
||||
if( !p.canPlayerEdit( offsetPos, side, item ) )
|
||||
{
|
||||
return ActionResultType.FAIL;
|
||||
}
|
||||
if (!p.canPlayerEdit(offsetPos, side, item)) {
|
||||
return ActionResultType.FAIL;
|
||||
}
|
||||
|
||||
if( w.isAirBlock( offsetPos ) )
|
||||
{
|
||||
this.extractAEPower( item, 1600, Actionable.MODULATE );
|
||||
w.playSound( p, offsetPos.getX() + 0.5D, offsetPos.getY() + 0.5D, offsetPos.getZ() + 0.5D, SoundEvents.ITEM_FLINTANDSTEEL_USE,
|
||||
SoundCategory.PLAYERS, 1.0F, random.nextFloat() * 0.4F + 0.8F );
|
||||
w.setBlockState( offsetPos, Blocks.FIRE.getDefaultState() );
|
||||
}
|
||||
if (w.isAirBlock(offsetPos)) {
|
||||
this.extractAEPower(item, 1600, Actionable.MODULATE);
|
||||
w.playSound(p, offsetPos.getX() + 0.5D, offsetPos.getY() + 0.5D, offsetPos.getZ() + 0.5D,
|
||||
SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.PLAYERS, 1.0F,
|
||||
random.nextFloat() * 0.4F + 0.8F);
|
||||
w.setBlockState(offsetPos, Blocks.FIRE.getDefaultState());
|
||||
}
|
||||
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
package appeng.items.tools.powered;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -44,6 +44,7 @@ import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.api.implementations.items.IStorageCell;
|
||||
import appeng.api.storage.ICellInventoryHandler;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
@@ -55,7 +56,6 @@ import appeng.api.util.DimensionalCoord;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.core.localization.PlayerMessages;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketMatterCannon;
|
||||
@@ -70,455 +70,389 @@ import appeng.tile.misc.TilePaint;
|
||||
import appeng.util.LookDirection;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell<IAEItemStack>
|
||||
{
|
||||
|
||||
public ToolMatterCannon(Item.Properties props)
|
||||
{
|
||||
super( AEConfig.instance().getMatterCannonBattery(), props );
|
||||
}
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
@Override
|
||||
public void addInformation( final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
|
||||
{
|
||||
super.addInformation( stack, world, lines, advancedTooltips );
|
||||
|
||||
final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory( stack, null, AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
|
||||
AEApi.instance().client().addCellInformation( cdi, lines );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick( final World w, final PlayerEntity p, final @Nullable Hand hand )
|
||||
{
|
||||
if( this.getAECurrentPower( p.getHeldItem( hand ) ) > 1600 )
|
||||
{
|
||||
int shots = 1;
|
||||
|
||||
final CellUpgrades cu = (CellUpgrades) this.getUpgradesInventory( p.getHeldItem( hand ) );
|
||||
if( cu != null )
|
||||
{
|
||||
shots += cu.getInstalledUpgrades( Upgrades.SPEED );
|
||||
}
|
||||
|
||||
final ICellInventoryHandler<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( p.getHeldItem( hand ), null, AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
if( inv != null )
|
||||
{
|
||||
final IItemList<IAEItemStack> itemList = inv.getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
|
||||
IAEItemStack req = itemList.getFirstItem();
|
||||
if( req instanceof IAEItemStack )
|
||||
{
|
||||
shots = Math.min( shots, (int) req.getStackSize() );
|
||||
for( int sh = 0; sh < shots; sh++ )
|
||||
{
|
||||
IAEItemStack aeAmmo = req.copy();
|
||||
this.extractAEPower( p.getHeldItem( hand ), 1600, Actionable.MODULATE );
|
||||
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return new ActionResult<>( ActionResultType.SUCCESS, p.getHeldItem( hand ) );
|
||||
}
|
||||
|
||||
aeAmmo.setStackSize( 1 );
|
||||
final ItemStack ammo = aeAmmo.createItemStack();
|
||||
if( ammo == null )
|
||||
{
|
||||
return new ActionResult<>( ActionResultType.SUCCESS, p.getHeldItem( hand ) );
|
||||
}
|
||||
|
||||
aeAmmo = inv.extractItems( aeAmmo, Actionable.MODULATE, new PlayerSource( p, null ) );
|
||||
if( aeAmmo == null )
|
||||
{
|
||||
return new ActionResult<>( ActionResultType.SUCCESS, p.getHeldItem( hand ) );
|
||||
}
|
||||
|
||||
final LookDirection dir = Platform.getPlayerRay( p );
|
||||
|
||||
final Vec3d Vec3d = dir.getA();
|
||||
final Vec3d Vec3d1 = dir.getB();
|
||||
final Vec3d direction = Vec3d1.subtract( Vec3d );
|
||||
direction.normalize();
|
||||
|
||||
final double d0 = Vec3d.x;
|
||||
final double d1 = Vec3d.y;
|
||||
final double d2 = Vec3d.z;
|
||||
|
||||
final float penetration = AEApi.instance().registries().matterCannon().getPenetration( ammo ); // 196.96655f;
|
||||
if( penetration <= 0 )
|
||||
{
|
||||
final ItemStack type = aeAmmo.asItemStackRepresentation();
|
||||
if( type.getItem() instanceof ItemPaintBall )
|
||||
{
|
||||
this.shootPaintBalls( type, w, p, Vec3d, Vec3d1, direction, d0, d1, d2 );
|
||||
}
|
||||
return new ActionResult<>( ActionResultType.SUCCESS, p.getHeldItem( hand ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.standardAmmo( penetration, w, p, Vec3d, Vec3d1, direction, d0, d1, d2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
p.sendMessage( PlayerMessages.AmmoDepleted.get() );
|
||||
}
|
||||
return new ActionResult<>( ActionResultType.SUCCESS, p.getHeldItem( hand ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ActionResult<>( ActionResultType.FAIL, p.getHeldItem( hand ) );
|
||||
}
|
||||
|
||||
private void shootPaintBalls( final ItemStack type, final World w, final PlayerEntity p, final Vec3d Vec3d, final Vec3d Vec3d1, final Vec3d direction, final double d0, final double d1, final double d2 )
|
||||
{
|
||||
final AxisAlignedBB bb = new AxisAlignedBB( Math.min( Vec3d.x, Vec3d1.x ), Math.min( Vec3d.y, Vec3d1.y ), Math.min( Vec3d.z, Vec3d1.z ), Math.max( Vec3d.x, Vec3d1.x ), Math.max( Vec3d.y, Vec3d1.y ), Math.max( Vec3d.z, Vec3d1.z ) ).grow( 16, 16, 16 );
|
||||
|
||||
Entity entity = null;
|
||||
Vec3d entityIntersection = null;
|
||||
final List list = w.getEntitiesWithinAABBExcludingEntity( p, bb );
|
||||
double closest = 9999999.0D;
|
||||
|
||||
for( int l = 0; l < list.size(); ++l )
|
||||
{
|
||||
final Entity entity1 = (Entity) list.get( l );
|
||||
|
||||
if( !entity1.isAlive() && entity1 != p && !( entity1 instanceof ItemEntity ) )
|
||||
{
|
||||
if( entity1.isAlive() )
|
||||
{
|
||||
// prevent killing / flying of mounts.
|
||||
if( entity1.isRidingOrBeingRiddenBy( p ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final float f1 = 0.3F;
|
||||
|
||||
final AxisAlignedBB boundingBox = entity1.getBoundingBox().grow( f1, f1, f1 );
|
||||
final Vec3d intersection = boundingBox.rayTrace( Vec3d, Vec3d1 ).orElse(null);
|
||||
|
||||
if( intersection != null )
|
||||
{
|
||||
final double nd = Vec3d.squareDistanceTo( intersection );
|
||||
|
||||
if( nd < closest )
|
||||
{
|
||||
entity = entity1;
|
||||
entityIntersection = intersection;
|
||||
closest = nd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RayTraceContext rayTraceContext = new RayTraceContext(Vec3d, Vec3d1, RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, p);
|
||||
RayTraceResult pos = w.rayTraceBlocks( rayTraceContext );
|
||||
|
||||
final Vec3d vec = new Vec3d( d0, d1, d2 );
|
||||
if( entity != null && pos.getType() != RayTraceResult.Type.MISS && pos.getHitVec().squareDistanceTo( vec ) > closest )
|
||||
{
|
||||
pos = new EntityRayTraceResult( entity, entityIntersection );
|
||||
}
|
||||
else if( entity != null && pos.getType() == RayTraceResult.Type.MISS )
|
||||
{
|
||||
pos = new EntityRayTraceResult( entity, entityIntersection );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AppEng.proxy.sendToAllNearExcept( null, d0, d1, d2, 128, w, new PacketMatterCannon( d0, d1, d2, (float) direction.x, (float) direction.y, (float) direction.z, (byte) ( pos.getType() == RayTraceResult.Type.MISS ? 32 : pos.getHitVec().squareDistanceTo( vec ) + 1 ) ) );
|
||||
}
|
||||
catch( final Exception err )
|
||||
{
|
||||
AELog.debug( err );
|
||||
}
|
||||
|
||||
if( pos.getType() != RayTraceResult.Type.MISS && type != null && type.getItem() instanceof ItemPaintBall )
|
||||
{
|
||||
final ItemPaintBall ipb = (ItemPaintBall) type.getItem();
|
||||
|
||||
final AEColor col = ipb.getColor();
|
||||
// boolean lit = ipb.isLumen( type );
|
||||
|
||||
if( pos instanceof EntityRayTraceResult )
|
||||
{
|
||||
EntityRayTraceResult entityResult = (EntityRayTraceResult) pos;
|
||||
Entity entityHit = entityResult.getEntity();
|
||||
|
||||
final int id = entityHit.getEntityId();
|
||||
final PlayerColor marker = new PlayerColor( id, col, 20 * 30 );
|
||||
TickHandler.INSTANCE.getPlayerColors().put( id, marker );
|
||||
|
||||
if( entityHit instanceof SheepEntity)
|
||||
{
|
||||
final SheepEntity sh = (SheepEntity) entityHit;
|
||||
sh.setFleeceColor( col.dye );
|
||||
}
|
||||
|
||||
entityHit.attackEntityFrom( DamageSource.causePlayerDamage( p ), 0 );
|
||||
NetworkHandler.instance().sendToAll( marker.getPacket() );
|
||||
}
|
||||
else if( pos instanceof BlockRayTraceResult )
|
||||
{
|
||||
BlockRayTraceResult blockResult = (BlockRayTraceResult) pos;
|
||||
final Direction side = blockResult.getFace();
|
||||
final BlockPos hitPos = blockResult.getPos().offset( side );
|
||||
|
||||
if( !Platform.hasPermissions( new DimensionalCoord( w, hitPos ), p ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final BlockState whatsThere = w.getBlockState( hitPos );
|
||||
if( whatsThere.getMaterial().isReplaceable() && w.isAirBlock( hitPos ) )
|
||||
{
|
||||
AEApi.instance().definitions().blocks().paint().maybeBlock().ifPresent( paintBlock -> {
|
||||
w.setBlockState( hitPos, paintBlock.getDefaultState(), 3 );
|
||||
} );
|
||||
}
|
||||
|
||||
final TileEntity te = w.getTileEntity( hitPos );
|
||||
if( te instanceof TilePaint )
|
||||
{
|
||||
final Vec3d hp = pos.getHitVec().subtract( hitPos.getX(), hitPos.getY(), hitPos.getZ() );
|
||||
( (TilePaint) te ).addBlot( type, side.getOpposite(), hp );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void standardAmmo( float penetration, final World w, final PlayerEntity p, final Vec3d Vec3d, final Vec3d Vec3d1, final Vec3d direction, final double d0, final double d1, final double d2 )
|
||||
{
|
||||
boolean hasDestroyed = true;
|
||||
while( penetration > 0 && hasDestroyed )
|
||||
{
|
||||
hasDestroyed = false;
|
||||
|
||||
final AxisAlignedBB bb = new AxisAlignedBB( Math.min( Vec3d.x, Vec3d1.x ), Math.min( Vec3d.y, Vec3d1.y ), Math.min( Vec3d.z, Vec3d1.z ), Math.max( Vec3d.x, Vec3d1.x ), Math.max( Vec3d.y, Vec3d1.y ), Math.max( Vec3d.z, Vec3d1.z ) ).grow( 16, 16, 16 );
|
||||
|
||||
Entity entity = null;
|
||||
Vec3d entityIntersection = null;
|
||||
final List list = w.getEntitiesWithinAABBExcludingEntity( p, bb );
|
||||
double closest = 9999999.0D;
|
||||
|
||||
for( int l = 0; l < list.size(); ++l )
|
||||
{
|
||||
final Entity entity1 = (Entity) list.get( l );
|
||||
|
||||
if( entity1.isAlive() && entity1 != p && !( entity1 instanceof ItemEntity ) )
|
||||
{
|
||||
if( entity1.isAlive() )
|
||||
{
|
||||
// prevent killing / flying of mounts.
|
||||
if( entity1.isRidingOrBeingRiddenBy( p ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final float f1 = 0.3F;
|
||||
|
||||
final AxisAlignedBB boundingBox = entity1.getBoundingBox().grow( f1, f1, f1 );
|
||||
final Vec3d intersection = boundingBox.rayTrace( Vec3d, Vec3d1 ).orElse(null);
|
||||
|
||||
if( intersection != null )
|
||||
{
|
||||
final double nd = Vec3d.squareDistanceTo( intersection );
|
||||
|
||||
if( nd < closest )
|
||||
{
|
||||
entity = entity1;
|
||||
entityIntersection = intersection;
|
||||
closest = nd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RayTraceContext rayTraceContext = new RayTraceContext(Vec3d, Vec3d1, RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, p);
|
||||
final Vec3d vec = new Vec3d( d0, d1, d2 );
|
||||
RayTraceResult pos = w.rayTraceBlocks( rayTraceContext );
|
||||
if( entity != null && pos.getType() != RayTraceResult.Type.MISS && pos.getHitVec().squareDistanceTo( vec ) > closest )
|
||||
{
|
||||
pos = new EntityRayTraceResult( entity, entityIntersection );
|
||||
}
|
||||
else if( entity != null && pos.getType() == RayTraceResult.Type.MISS )
|
||||
{
|
||||
pos = new EntityRayTraceResult( entity, entityIntersection );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AppEng.proxy.sendToAllNearExcept( null, d0, d1, d2, 128, w, new PacketMatterCannon( d0, d1, d2, (float) direction.x, (float) direction.y, (float) direction.z, (byte) ( pos.getType() == RayTraceResult.Type.MISS ? 32 : pos.getHitVec().squareDistanceTo( vec ) + 1 ) ) );
|
||||
}
|
||||
catch( final Exception err )
|
||||
{
|
||||
AELog.debug( err );
|
||||
}
|
||||
|
||||
if( pos.getType() != RayTraceResult.Type.MISS )
|
||||
{
|
||||
final DamageSource dmgSrc = new EntityDamageSource( "matter_cannon", p );
|
||||
|
||||
if( pos instanceof EntityRayTraceResult )
|
||||
{
|
||||
EntityRayTraceResult entityResult = (EntityRayTraceResult) pos;
|
||||
Entity entityHit = entityResult.getEntity();
|
||||
|
||||
final int dmg = (int) Math.ceil( penetration / 20.0f );
|
||||
if( entityHit instanceof LivingEntity )
|
||||
{
|
||||
final LivingEntity el = (LivingEntity) entityHit;
|
||||
penetration -= dmg;
|
||||
el.knockBack( p, 0, -direction.x, -direction.z );
|
||||
// el.knockBack( p, 0, Vec3d.x,
|
||||
// Vec3d.z );
|
||||
el.attackEntityFrom( dmgSrc, dmg );
|
||||
if( !el.isAlive() )
|
||||
{
|
||||
hasDestroyed = true;
|
||||
}
|
||||
}
|
||||
else if( entityHit instanceof ItemEntity )
|
||||
{
|
||||
hasDestroyed = true;
|
||||
entityHit.remove();
|
||||
}
|
||||
else if( entityHit.attackEntityFrom( dmgSrc, dmg ) )
|
||||
{
|
||||
hasDestroyed = true;
|
||||
}
|
||||
}
|
||||
else if( pos instanceof BlockRayTraceResult )
|
||||
{
|
||||
BlockRayTraceResult blockResult = (BlockRayTraceResult) pos;
|
||||
|
||||
if( !AEConfig.instance().isFeatureEnabled( AEFeature.MASS_CANNON_BLOCK_DAMAGE ) )
|
||||
{
|
||||
penetration = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
BlockPos blockPos = blockResult.getPos();
|
||||
final BlockState bs = w.getBlockState(blockPos);
|
||||
|
||||
final float hardness = bs.getBlockHardness( w, blockPos) * 9.0f;
|
||||
if( hardness >= 0.0 )
|
||||
{
|
||||
if( penetration > hardness && Platform.hasPermissions( new DimensionalCoord( w, blockPos), p ) )
|
||||
{
|
||||
hasDestroyed = true;
|
||||
penetration -= hardness;
|
||||
penetration *= 0.60;
|
||||
w.destroyBlock(blockPos, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable( final ItemStack is )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getUpgradesInventory( final ItemStack is )
|
||||
{
|
||||
return new CellUpgrades( is, 4 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getConfigInventory( final ItemStack is )
|
||||
{
|
||||
return new CellConfig( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode( final ItemStack is )
|
||||
{
|
||||
final String fz = is.getOrCreateTag().getString( "FuzzyMode" );
|
||||
try
|
||||
{
|
||||
return FuzzyMode.valueOf( fz );
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuzzyMode( final ItemStack is, final FuzzyMode fzMode )
|
||||
{
|
||||
is.getOrCreateTag().putString( "FuzzyMode", fzMode.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytes( final ItemStack cellItem )
|
||||
{
|
||||
return 512;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytesPerType( final ItemStack cellItem )
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalTypes( final ItemStack cellItem )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlackListed( final ItemStack cellItem, final IAEItemStack requestedAddition )
|
||||
{
|
||||
final float pen = AEApi.instance().registries().matterCannon().getPenetration( requestedAddition.createItemStack() );
|
||||
if( pen > 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( requestedAddition.getItem() instanceof ItemPaintBall )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storableInStorageCell()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageCell( final ItemStack i )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain()
|
||||
{
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell<IAEItemStack> {
|
||||
|
||||
public ToolMatterCannon(Item.Properties props) {
|
||||
super(AEConfig.instance().getMatterCannonBattery(), props);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines,
|
||||
final ITooltipFlag advancedTooltips) {
|
||||
super.addInformation(stack, world, lines, advancedTooltips);
|
||||
|
||||
final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory(stack,
|
||||
null, AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
|
||||
AEApi.instance().client().addCellInformation(cdi, lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(final World w, final PlayerEntity p, final @Nullable Hand hand) {
|
||||
if (this.getAECurrentPower(p.getHeldItem(hand)) > 1600) {
|
||||
int shots = 1;
|
||||
|
||||
final CellUpgrades cu = (CellUpgrades) this.getUpgradesInventory(p.getHeldItem(hand));
|
||||
if (cu != null) {
|
||||
shots += cu.getInstalledUpgrades(Upgrades.SPEED);
|
||||
}
|
||||
|
||||
final ICellInventoryHandler<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory(
|
||||
p.getHeldItem(hand), null, AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
if (inv != null) {
|
||||
final IItemList<IAEItemStack> itemList = inv.getAvailableItems(
|
||||
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList());
|
||||
IAEItemStack req = itemList.getFirstItem();
|
||||
if (req instanceof IAEItemStack) {
|
||||
shots = Math.min(shots, (int) req.getStackSize());
|
||||
for (int sh = 0; sh < shots; sh++) {
|
||||
IAEItemStack aeAmmo = req.copy();
|
||||
this.extractAEPower(p.getHeldItem(hand), 1600, Actionable.MODULATE);
|
||||
|
||||
if (Platform.isClient()) {
|
||||
return new ActionResult<>(ActionResultType.SUCCESS, p.getHeldItem(hand));
|
||||
}
|
||||
|
||||
aeAmmo.setStackSize(1);
|
||||
final ItemStack ammo = aeAmmo.createItemStack();
|
||||
if (ammo == null) {
|
||||
return new ActionResult<>(ActionResultType.SUCCESS, p.getHeldItem(hand));
|
||||
}
|
||||
|
||||
aeAmmo = inv.extractItems(aeAmmo, Actionable.MODULATE, new PlayerSource(p, null));
|
||||
if (aeAmmo == null) {
|
||||
return new ActionResult<>(ActionResultType.SUCCESS, p.getHeldItem(hand));
|
||||
}
|
||||
|
||||
final LookDirection dir = Platform.getPlayerRay(p);
|
||||
|
||||
final Vec3d Vec3d = dir.getA();
|
||||
final Vec3d Vec3d1 = dir.getB();
|
||||
final Vec3d direction = Vec3d1.subtract(Vec3d);
|
||||
direction.normalize();
|
||||
|
||||
final double d0 = Vec3d.x;
|
||||
final double d1 = Vec3d.y;
|
||||
final double d2 = Vec3d.z;
|
||||
|
||||
final float penetration = AEApi.instance().registries().matterCannon().getPenetration(ammo); // 196.96655f;
|
||||
if (penetration <= 0) {
|
||||
final ItemStack type = aeAmmo.asItemStackRepresentation();
|
||||
if (type.getItem() instanceof ItemPaintBall) {
|
||||
this.shootPaintBalls(type, w, p, Vec3d, Vec3d1, direction, d0, d1, d2);
|
||||
}
|
||||
return new ActionResult<>(ActionResultType.SUCCESS, p.getHeldItem(hand));
|
||||
} else {
|
||||
this.standardAmmo(penetration, w, p, Vec3d, Vec3d1, direction, d0, d1, d2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Platform.isServer()) {
|
||||
p.sendMessage(PlayerMessages.AmmoDepleted.get());
|
||||
}
|
||||
return new ActionResult<>(ActionResultType.SUCCESS, p.getHeldItem(hand));
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ActionResult<>(ActionResultType.FAIL, p.getHeldItem(hand));
|
||||
}
|
||||
|
||||
private void shootPaintBalls(final ItemStack type, final World w, final PlayerEntity p, final Vec3d Vec3d,
|
||||
final Vec3d Vec3d1, final Vec3d direction, final double d0, final double d1, final double d2) {
|
||||
final AxisAlignedBB bb = new AxisAlignedBB(Math.min(Vec3d.x, Vec3d1.x), Math.min(Vec3d.y, Vec3d1.y),
|
||||
Math.min(Vec3d.z, Vec3d1.z), Math.max(Vec3d.x, Vec3d1.x), Math.max(Vec3d.y, Vec3d1.y),
|
||||
Math.max(Vec3d.z, Vec3d1.z)).grow(16, 16, 16);
|
||||
|
||||
Entity entity = null;
|
||||
Vec3d entityIntersection = null;
|
||||
final List list = w.getEntitiesWithinAABBExcludingEntity(p, bb);
|
||||
double closest = 9999999.0D;
|
||||
|
||||
for (int l = 0; l < list.size(); ++l) {
|
||||
final Entity entity1 = (Entity) list.get(l);
|
||||
|
||||
if (!entity1.isAlive() && entity1 != p && !(entity1 instanceof ItemEntity)) {
|
||||
if (entity1.isAlive()) {
|
||||
// prevent killing / flying of mounts.
|
||||
if (entity1.isRidingOrBeingRiddenBy(p)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final float f1 = 0.3F;
|
||||
|
||||
final AxisAlignedBB boundingBox = entity1.getBoundingBox().grow(f1, f1, f1);
|
||||
final Vec3d intersection = boundingBox.rayTrace(Vec3d, Vec3d1).orElse(null);
|
||||
|
||||
if (intersection != null) {
|
||||
final double nd = Vec3d.squareDistanceTo(intersection);
|
||||
|
||||
if (nd < closest) {
|
||||
entity = entity1;
|
||||
entityIntersection = intersection;
|
||||
closest = nd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RayTraceContext rayTraceContext = new RayTraceContext(Vec3d, Vec3d1, RayTraceContext.BlockMode.COLLIDER,
|
||||
RayTraceContext.FluidMode.NONE, p);
|
||||
RayTraceResult pos = w.rayTraceBlocks(rayTraceContext);
|
||||
|
||||
final Vec3d vec = new Vec3d(d0, d1, d2);
|
||||
if (entity != null && pos.getType() != RayTraceResult.Type.MISS
|
||||
&& pos.getHitVec().squareDistanceTo(vec) > closest) {
|
||||
pos = new EntityRayTraceResult(entity, entityIntersection);
|
||||
} else if (entity != null && pos.getType() == RayTraceResult.Type.MISS) {
|
||||
pos = new EntityRayTraceResult(entity, entityIntersection);
|
||||
}
|
||||
|
||||
try {
|
||||
AppEng.proxy.sendToAllNearExcept(null, d0, d1, d2, 128, w,
|
||||
new PacketMatterCannon(d0, d1, d2, (float) direction.x, (float) direction.y, (float) direction.z,
|
||||
(byte) (pos.getType() == RayTraceResult.Type.MISS ? 32
|
||||
: pos.getHitVec().squareDistanceTo(vec) + 1)));
|
||||
} catch (final Exception err) {
|
||||
AELog.debug(err);
|
||||
}
|
||||
|
||||
if (pos.getType() != RayTraceResult.Type.MISS && type != null && type.getItem() instanceof ItemPaintBall) {
|
||||
final ItemPaintBall ipb = (ItemPaintBall) type.getItem();
|
||||
|
||||
final AEColor col = ipb.getColor();
|
||||
// boolean lit = ipb.isLumen( type );
|
||||
|
||||
if (pos instanceof EntityRayTraceResult) {
|
||||
EntityRayTraceResult entityResult = (EntityRayTraceResult) pos;
|
||||
Entity entityHit = entityResult.getEntity();
|
||||
|
||||
final int id = entityHit.getEntityId();
|
||||
final PlayerColor marker = new PlayerColor(id, col, 20 * 30);
|
||||
TickHandler.INSTANCE.getPlayerColors().put(id, marker);
|
||||
|
||||
if (entityHit instanceof SheepEntity) {
|
||||
final SheepEntity sh = (SheepEntity) entityHit;
|
||||
sh.setFleeceColor(col.dye);
|
||||
}
|
||||
|
||||
entityHit.attackEntityFrom(DamageSource.causePlayerDamage(p), 0);
|
||||
NetworkHandler.instance().sendToAll(marker.getPacket());
|
||||
} else if (pos instanceof BlockRayTraceResult) {
|
||||
BlockRayTraceResult blockResult = (BlockRayTraceResult) pos;
|
||||
final Direction side = blockResult.getFace();
|
||||
final BlockPos hitPos = blockResult.getPos().offset(side);
|
||||
|
||||
if (!Platform.hasPermissions(new DimensionalCoord(w, hitPos), p)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final BlockState whatsThere = w.getBlockState(hitPos);
|
||||
if (whatsThere.getMaterial().isReplaceable() && w.isAirBlock(hitPos)) {
|
||||
AEApi.instance().definitions().blocks().paint().maybeBlock().ifPresent(paintBlock -> {
|
||||
w.setBlockState(hitPos, paintBlock.getDefaultState(), 3);
|
||||
});
|
||||
}
|
||||
|
||||
final TileEntity te = w.getTileEntity(hitPos);
|
||||
if (te instanceof TilePaint) {
|
||||
final Vec3d hp = pos.getHitVec().subtract(hitPos.getX(), hitPos.getY(), hitPos.getZ());
|
||||
((TilePaint) te).addBlot(type, side.getOpposite(), hp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void standardAmmo(float penetration, final World w, final PlayerEntity p, final Vec3d Vec3d,
|
||||
final Vec3d Vec3d1, final Vec3d direction, final double d0, final double d1, final double d2) {
|
||||
boolean hasDestroyed = true;
|
||||
while (penetration > 0 && hasDestroyed) {
|
||||
hasDestroyed = false;
|
||||
|
||||
final AxisAlignedBB bb = new AxisAlignedBB(Math.min(Vec3d.x, Vec3d1.x), Math.min(Vec3d.y, Vec3d1.y),
|
||||
Math.min(Vec3d.z, Vec3d1.z), Math.max(Vec3d.x, Vec3d1.x), Math.max(Vec3d.y, Vec3d1.y),
|
||||
Math.max(Vec3d.z, Vec3d1.z)).grow(16, 16, 16);
|
||||
|
||||
Entity entity = null;
|
||||
Vec3d entityIntersection = null;
|
||||
final List list = w.getEntitiesWithinAABBExcludingEntity(p, bb);
|
||||
double closest = 9999999.0D;
|
||||
|
||||
for (int l = 0; l < list.size(); ++l) {
|
||||
final Entity entity1 = (Entity) list.get(l);
|
||||
|
||||
if (entity1.isAlive() && entity1 != p && !(entity1 instanceof ItemEntity)) {
|
||||
if (entity1.isAlive()) {
|
||||
// prevent killing / flying of mounts.
|
||||
if (entity1.isRidingOrBeingRiddenBy(p)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final float f1 = 0.3F;
|
||||
|
||||
final AxisAlignedBB boundingBox = entity1.getBoundingBox().grow(f1, f1, f1);
|
||||
final Vec3d intersection = boundingBox.rayTrace(Vec3d, Vec3d1).orElse(null);
|
||||
|
||||
if (intersection != null) {
|
||||
final double nd = Vec3d.squareDistanceTo(intersection);
|
||||
|
||||
if (nd < closest) {
|
||||
entity = entity1;
|
||||
entityIntersection = intersection;
|
||||
closest = nd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RayTraceContext rayTraceContext = new RayTraceContext(Vec3d, Vec3d1, RayTraceContext.BlockMode.COLLIDER,
|
||||
RayTraceContext.FluidMode.NONE, p);
|
||||
final Vec3d vec = new Vec3d(d0, d1, d2);
|
||||
RayTraceResult pos = w.rayTraceBlocks(rayTraceContext);
|
||||
if (entity != null && pos.getType() != RayTraceResult.Type.MISS
|
||||
&& pos.getHitVec().squareDistanceTo(vec) > closest) {
|
||||
pos = new EntityRayTraceResult(entity, entityIntersection);
|
||||
} else if (entity != null && pos.getType() == RayTraceResult.Type.MISS) {
|
||||
pos = new EntityRayTraceResult(entity, entityIntersection);
|
||||
}
|
||||
|
||||
try {
|
||||
AppEng.proxy.sendToAllNearExcept(null, d0, d1, d2, 128, w,
|
||||
new PacketMatterCannon(d0, d1, d2, (float) direction.x, (float) direction.y,
|
||||
(float) direction.z, (byte) (pos.getType() == RayTraceResult.Type.MISS ? 32
|
||||
: pos.getHitVec().squareDistanceTo(vec) + 1)));
|
||||
} catch (final Exception err) {
|
||||
AELog.debug(err);
|
||||
}
|
||||
|
||||
if (pos.getType() != RayTraceResult.Type.MISS) {
|
||||
final DamageSource dmgSrc = new EntityDamageSource("matter_cannon", p);
|
||||
|
||||
if (pos instanceof EntityRayTraceResult) {
|
||||
EntityRayTraceResult entityResult = (EntityRayTraceResult) pos;
|
||||
Entity entityHit = entityResult.getEntity();
|
||||
|
||||
final int dmg = (int) Math.ceil(penetration / 20.0f);
|
||||
if (entityHit instanceof LivingEntity) {
|
||||
final LivingEntity el = (LivingEntity) entityHit;
|
||||
penetration -= dmg;
|
||||
el.knockBack(p, 0, -direction.x, -direction.z);
|
||||
// el.knockBack( p, 0, Vec3d.x,
|
||||
// Vec3d.z );
|
||||
el.attackEntityFrom(dmgSrc, dmg);
|
||||
if (!el.isAlive()) {
|
||||
hasDestroyed = true;
|
||||
}
|
||||
} else if (entityHit instanceof ItemEntity) {
|
||||
hasDestroyed = true;
|
||||
entityHit.remove();
|
||||
} else if (entityHit.attackEntityFrom(dmgSrc, dmg)) {
|
||||
hasDestroyed = true;
|
||||
}
|
||||
} else if (pos instanceof BlockRayTraceResult) {
|
||||
BlockRayTraceResult blockResult = (BlockRayTraceResult) pos;
|
||||
|
||||
if (!AEConfig.instance().isFeatureEnabled(AEFeature.MASS_CANNON_BLOCK_DAMAGE)) {
|
||||
penetration = 0;
|
||||
} else {
|
||||
BlockPos blockPos = blockResult.getPos();
|
||||
final BlockState bs = w.getBlockState(blockPos);
|
||||
|
||||
final float hardness = bs.getBlockHardness(w, blockPos) * 9.0f;
|
||||
if (hardness >= 0.0) {
|
||||
if (penetration > hardness
|
||||
&& Platform.hasPermissions(new DimensionalCoord(w, blockPos), p)) {
|
||||
hasDestroyed = true;
|
||||
penetration -= hardness;
|
||||
penetration *= 0.60;
|
||||
w.destroyBlock(blockPos, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable(final ItemStack is) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getUpgradesInventory(final ItemStack is) {
|
||||
return new CellUpgrades(is, 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getConfigInventory(final ItemStack is) {
|
||||
return new CellConfig(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode(final ItemStack is) {
|
||||
final String fz = is.getOrCreateTag().getString("FuzzyMode");
|
||||
try {
|
||||
return FuzzyMode.valueOf(fz);
|
||||
} catch (final Throwable t) {
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
|
||||
is.getOrCreateTag().putString("FuzzyMode", fzMode.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytes(final ItemStack cellItem) {
|
||||
return 512;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytesPerType(final ItemStack cellItem) {
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalTypes(final ItemStack cellItem) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlackListed(final ItemStack cellItem, final IAEItemStack requestedAddition) {
|
||||
final float pen = AEApi.instance().registries().matterCannon()
|
||||
.getPenetration(requestedAddition.createItemStack());
|
||||
if (pen > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (requestedAddition.getItem() instanceof ItemPaintBall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storableInStorageCell() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageCell(final ItemStack i) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain() {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,20 +18,15 @@
|
||||
|
||||
package appeng.items.tools.powered;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerMEPortableCell;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
@@ -51,146 +46,122 @@ import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerMEPortableCell;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.localization.GuiText;
|
||||
|
||||
import appeng.items.contents.CellConfig;
|
||||
import appeng.items.contents.CellUpgrades;
|
||||
import appeng.items.contents.PortableCellViewer;
|
||||
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell<IAEItemStack>, IGuiItem, IItemGroup {
|
||||
public ToolPortableCell(Item.Properties props) {
|
||||
super(AEConfig.instance().getPortableCellBattery(), props);
|
||||
}
|
||||
|
||||
public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell<IAEItemStack>, IGuiItem, IItemGroup
|
||||
{
|
||||
public ToolPortableCell(Item.Properties props)
|
||||
{
|
||||
super( AEConfig.instance().getPortableCellBattery(), props );
|
||||
}
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(final World w, final PlayerEntity player, final Hand hand) {
|
||||
ContainerOpener.openContainer(ContainerMEPortableCell.TYPE, player, ContainerLocator.forHand(player, hand));
|
||||
return new ActionResult<>(ActionResultType.SUCCESS, player.getHeldItem(hand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick( final World w, final PlayerEntity player, final Hand hand )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerMEPortableCell.TYPE, player, ContainerLocator.forHand(player, hand));
|
||||
return new ActionResult<>( ActionResultType.SUCCESS, player.getHeldItem( hand ) );
|
||||
}
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines,
|
||||
final ITooltipFlag advancedTooltips) {
|
||||
super.addInformation(stack, world, lines, advancedTooltips);
|
||||
|
||||
@Override
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
|
||||
{
|
||||
super.addInformation( stack, world, lines, advancedTooltips );
|
||||
final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance().registries().cell().getCellInventory(stack,
|
||||
null, AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
|
||||
final ICellInventoryHandler<IAEItemStack> cdi = AEApi.instance()
|
||||
.registries()
|
||||
.cell()
|
||||
.getCellInventory( stack, null,
|
||||
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
AEApi.instance().client().addCellInformation(cdi, lines);
|
||||
}
|
||||
|
||||
AEApi.instance().client().addCellInformation( cdi, lines );
|
||||
}
|
||||
@Override
|
||||
public int getBytes(final ItemStack cellItem) {
|
||||
return 512;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytes( final ItemStack cellItem )
|
||||
{
|
||||
return 512;
|
||||
}
|
||||
@Override
|
||||
public int getBytesPerType(final ItemStack cellItem) {
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytesPerType( final ItemStack cellItem )
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
@Override
|
||||
public int getTotalTypes(final ItemStack cellItem) {
|
||||
return 27;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalTypes( final ItemStack cellItem )
|
||||
{
|
||||
return 27;
|
||||
}
|
||||
@Override
|
||||
public boolean isBlackListed(final ItemStack cellItem, final IAEItemStack requestedAddition) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlackListed( final ItemStack cellItem, final IAEItemStack requestedAddition )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean storableInStorageCell() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storableInStorageCell()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isStorageCell(final ItemStack i) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageCell( final ItemStack i )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public double getIdleDrain() {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain()
|
||||
{
|
||||
return 0.5;
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public String getUnlocalizedGroupName(final Set<ItemStack> others, final ItemStack is) {
|
||||
return GuiText.StorageCells.getTranslationKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedGroupName( final Set<ItemStack> others, final ItemStack is )
|
||||
{
|
||||
return GuiText.StorageCells.getTranslationKey();
|
||||
}
|
||||
@Override
|
||||
public boolean isEditable(final ItemStack is) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable( final ItemStack is )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getUpgradesInventory(final ItemStack is) {
|
||||
return new CellUpgrades(is, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getUpgradesInventory( final ItemStack is )
|
||||
{
|
||||
return new CellUpgrades( is, 2 );
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getConfigInventory(final ItemStack is) {
|
||||
return new CellConfig(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getConfigInventory( final ItemStack is )
|
||||
{
|
||||
return new CellConfig( is );
|
||||
}
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode(final ItemStack is) {
|
||||
final String fz = is.getOrCreateTag().getString("FuzzyMode");
|
||||
try {
|
||||
return FuzzyMode.valueOf(fz);
|
||||
} catch (final Throwable t) {
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode( final ItemStack is )
|
||||
{
|
||||
final String fz = is.getOrCreateTag().getString( "FuzzyMode" );
|
||||
try
|
||||
{
|
||||
return FuzzyMode.valueOf( fz );
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuzzyMode( final ItemStack is, final FuzzyMode fzMode )
|
||||
{
|
||||
@Override
|
||||
public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
|
||||
is.getOrCreateTag().putString("FuzzyMode", fzMode.name());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGuiItemObject getGuiObject( final ItemStack is, int playerInventorySlot, final World w, final BlockPos pos )
|
||||
{
|
||||
return new PortableCellViewer( is, playerInventorySlot );
|
||||
}
|
||||
@Override
|
||||
public IGuiItemObject getGuiObject(final ItemStack is, int playerInventorySlot, final World w, final BlockPos pos) {
|
||||
return new PortableCellViewer(is, playerInventorySlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCauseReequipAnimation( ItemStack oldStack, ItemStack newStack, boolean slotChanged )
|
||||
{
|
||||
return slotChanged;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
|
||||
return slotChanged;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.items.tools.powered;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
@@ -48,103 +47,85 @@ import appeng.core.localization.GuiText;
|
||||
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
|
||||
import appeng.util.ConfigManager;
|
||||
|
||||
public class ToolWirelessTerminal extends AEBasePoweredItem implements IWirelessTermHandler {
|
||||
|
||||
public class ToolWirelessTerminal extends AEBasePoweredItem implements IWirelessTermHandler
|
||||
{
|
||||
public ToolWirelessTerminal(Item.Properties props) {
|
||||
super(AEConfig.instance().getWirelessTerminalBattery(), props);
|
||||
}
|
||||
|
||||
public ToolWirelessTerminal(Item.Properties props)
|
||||
{
|
||||
super( AEConfig.instance().getWirelessTerminalBattery(), props );
|
||||
}
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(final World w, final PlayerEntity player, final Hand hand) {
|
||||
AEApi.instance().registries().wireless().openWirelessTerminalGui(player.getHeldItem(hand), w, player, hand);
|
||||
return new ActionResult<>(ActionResultType.SUCCESS, player.getHeldItem(hand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick( final World w, final PlayerEntity player, final Hand hand )
|
||||
{
|
||||
AEApi.instance().registries().wireless().openWirelessTerminalGui( player.getHeldItem( hand ), w, player, hand );
|
||||
return new ActionResult<>( ActionResultType.SUCCESS, player.getHeldItem( hand ) );
|
||||
}
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines,
|
||||
final ITooltipFlag advancedTooltips) {
|
||||
super.addInformation(stack, world, lines, advancedTooltips);
|
||||
|
||||
@Override
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public void addInformation( final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
|
||||
{
|
||||
super.addInformation( stack, world, lines, advancedTooltips );
|
||||
if (stack.hasTag()) {
|
||||
final CompoundNBT tag = stack.getOrCreateTag();
|
||||
if (tag != null) {
|
||||
final String encKey = tag.getString("encryptionKey");
|
||||
|
||||
if( stack.hasTag() )
|
||||
{
|
||||
final CompoundNBT tag = stack.getOrCreateTag();
|
||||
if( tag != null )
|
||||
{
|
||||
final String encKey = tag.getString( "encryptionKey" );
|
||||
if (encKey == null || encKey.isEmpty()) {
|
||||
lines.add(GuiText.Unlinked.textComponent());
|
||||
} else {
|
||||
lines.add(GuiText.Linked.textComponent());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lines.add(new TranslationTextComponent("AppEng.GuiITooltip.Unlinked"));
|
||||
}
|
||||
}
|
||||
|
||||
if( encKey == null || encKey.isEmpty() )
|
||||
{
|
||||
lines.add( GuiText.Unlinked.textComponent() );
|
||||
}
|
||||
else
|
||||
{
|
||||
lines.add( GuiText.Linked.textComponent() );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lines.add( new TranslationTextComponent( "AppEng.GuiITooltip.Unlinked" ) );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean canHandle(final ItemStack is) {
|
||||
return AEApi.instance().definitions().items().wirelessTerminal().isSameAs(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHandle( final ItemStack is )
|
||||
{
|
||||
return AEApi.instance().definitions().items().wirelessTerminal().isSameAs( is );
|
||||
}
|
||||
@Override
|
||||
public boolean usePower(final PlayerEntity player, final double amount, final ItemStack is) {
|
||||
return this.extractAEPower(is, amount, Actionable.MODULATE) >= amount - 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usePower( final PlayerEntity player, final double amount, final ItemStack is )
|
||||
{
|
||||
return this.extractAEPower( is, amount, Actionable.MODULATE ) >= amount - 0.5;
|
||||
}
|
||||
@Override
|
||||
public boolean hasPower(final PlayerEntity player, final double amt, final ItemStack is) {
|
||||
return this.getAECurrentPower(is) >= amt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPower( final PlayerEntity player, final double amt, final ItemStack is )
|
||||
{
|
||||
return this.getAECurrentPower( is ) >= amt;
|
||||
}
|
||||
@Override
|
||||
public IConfigManager getConfigManager(final ItemStack target) {
|
||||
final ConfigManager out = new ConfigManager((manager, settingName, newValue) -> {
|
||||
final CompoundNBT data = target.getOrCreateTag();
|
||||
manager.writeToNBT(data);
|
||||
});
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager( final ItemStack target )
|
||||
{
|
||||
final ConfigManager out = new ConfigManager( ( manager, settingName, newValue ) -> {
|
||||
final CompoundNBT data = target.getOrCreateTag();
|
||||
manager.writeToNBT( data );
|
||||
} );
|
||||
out.registerSetting(Settings.SORT_BY, SortOrder.NAME);
|
||||
out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
|
||||
out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
|
||||
|
||||
out.registerSetting( Settings.SORT_BY, SortOrder.NAME );
|
||||
out.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
|
||||
out.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
|
||||
out.readFromNBT(target.getOrCreateTag().copy());
|
||||
return out;
|
||||
}
|
||||
|
||||
out.readFromNBT( target.getOrCreateTag().copy() );
|
||||
return out;
|
||||
}
|
||||
@Override
|
||||
public String getEncryptionKey(final ItemStack item) {
|
||||
final CompoundNBT tag = item.getOrCreateTag();
|
||||
return tag.getString("encryptionKey");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEncryptionKey( final ItemStack item )
|
||||
{
|
||||
final CompoundNBT tag = item.getOrCreateTag();
|
||||
return tag.getString( "encryptionKey" );
|
||||
}
|
||||
@Override
|
||||
public void setEncryptionKey(final ItemStack item, final String encKey, final String name) {
|
||||
final CompoundNBT tag = item.getOrCreateTag();
|
||||
tag.putString("encryptionKey", encKey);
|
||||
tag.putString("name", name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEncryptionKey( final ItemStack item, final String encKey, final String name )
|
||||
{
|
||||
final CompoundNBT tag = item.getOrCreateTag();
|
||||
tag.putString( "encryptionKey", encKey );
|
||||
tag.putString( "name", name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCauseReequipAnimation( ItemStack oldStack, ItemStack newStack, boolean slotChanged )
|
||||
{
|
||||
return slotChanged;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
|
||||
return slotChanged;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.items.tools.powered.powersink;
|
||||
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.function.DoubleSupplier;
|
||||
@@ -31,9 +30,9 @@ import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -43,137 +42,122 @@ import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public abstract class AEBasePoweredItem extends AEBaseItem implements IAEItemPowerStorage {
|
||||
private static final String CURRENT_POWER_NBT_KEY = "internalCurrentPower";
|
||||
private static final String MAX_POWER_NBT_KEY = "internalMaxPower";
|
||||
private final DoubleSupplier powerCapacity;
|
||||
|
||||
public abstract class AEBasePoweredItem extends AEBaseItem implements IAEItemPowerStorage
|
||||
{
|
||||
private static final String CURRENT_POWER_NBT_KEY = "internalCurrentPower";
|
||||
private static final String MAX_POWER_NBT_KEY = "internalMaxPower";
|
||||
private final DoubleSupplier powerCapacity;
|
||||
|
||||
public AEBasePoweredItem(final DoubleSupplier powerCapacity, Properties props )
|
||||
{
|
||||
super(props);
|
||||
public AEBasePoweredItem(final DoubleSupplier powerCapacity, Properties props) {
|
||||
super(props);
|
||||
// FIXME this.setFull3D();
|
||||
|
||||
this.powerCapacity = powerCapacity;
|
||||
}
|
||||
this.powerCapacity = powerCapacity;
|
||||
}
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
@Override
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
|
||||
{
|
||||
final CompoundNBT tag = stack.getTag();
|
||||
double internalCurrentPower = 0;
|
||||
final double internalMaxPower = this.getAEMaxPower( stack );
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines,
|
||||
final ITooltipFlag advancedTooltips) {
|
||||
final CompoundNBT tag = stack.getTag();
|
||||
double internalCurrentPower = 0;
|
||||
final double internalMaxPower = this.getAEMaxPower(stack);
|
||||
|
||||
if( tag != null )
|
||||
{
|
||||
internalCurrentPower = tag.getDouble( CURRENT_POWER_NBT_KEY );
|
||||
}
|
||||
if (tag != null) {
|
||||
internalCurrentPower = tag.getDouble(CURRENT_POWER_NBT_KEY);
|
||||
}
|
||||
|
||||
final double percent = internalCurrentPower / internalMaxPower;
|
||||
final double percent = internalCurrentPower / internalMaxPower;
|
||||
|
||||
lines.add( GuiText.StoredEnergy.textComponent().appendText( ':' + MessageFormat.format( " {0,number,#} ", internalCurrentPower ) )
|
||||
.appendSibling( new TranslationTextComponent( PowerUnits.AE.unlocalizedName ) )
|
||||
.appendText( " - " + MessageFormat.format( " {0,number,#.##%} ", percent ) ) );
|
||||
}
|
||||
lines.add(GuiText.StoredEnergy.textComponent()
|
||||
.appendText(':' + MessageFormat.format(" {0,number,#} ", internalCurrentPower))
|
||||
.appendSibling(new TranslationTextComponent(PowerUnits.AE.unlocalizedName))
|
||||
.appendText(" - " + MessageFormat.format(" {0,number,#.##%} ", percent)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isDamageable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
|
||||
super.fillItemGroup(group, items);
|
||||
@Override
|
||||
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
|
||||
super.fillItemGroup(group, items);
|
||||
|
||||
if (this.isInGroup(group)) {
|
||||
final ItemStack charged = new ItemStack(this, 1);
|
||||
final CompoundNBT tag = charged.getOrCreateTag();
|
||||
tag.putDouble(CURRENT_POWER_NBT_KEY, this.getAEMaxPower(charged));
|
||||
tag.putDouble(MAX_POWER_NBT_KEY, this.getAEMaxPower(charged));
|
||||
if (this.isInGroup(group)) {
|
||||
final ItemStack charged = new ItemStack(this, 1);
|
||||
final CompoundNBT tag = charged.getOrCreateTag();
|
||||
tag.putDouble(CURRENT_POWER_NBT_KEY, this.getAEMaxPower(charged));
|
||||
tag.putDouble(MAX_POWER_NBT_KEY, this.getAEMaxPower(charged));
|
||||
|
||||
items.add(charged);
|
||||
}
|
||||
}
|
||||
items.add(charged);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDurabilityForDisplay( final ItemStack is )
|
||||
{
|
||||
return 1 - this.getAECurrentPower( is ) / this.getAEMaxPower( is );
|
||||
}
|
||||
@Override
|
||||
public double getDurabilityForDisplay(final ItemStack is) {
|
||||
return 1 - this.getAECurrentPower(is) / this.getAEMaxPower(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamaged( final ItemStack stack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isDamaged(final ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage( final ItemStack stack, final int damage )
|
||||
{
|
||||
@Override
|
||||
public void setDamage(final ItemStack stack, final int damage) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectAEPower( final ItemStack is, final double amount, Actionable mode )
|
||||
{
|
||||
final double maxStorage = this.getAEMaxPower( is );
|
||||
final double currentStorage = this.getAECurrentPower( is );
|
||||
final double required = maxStorage - currentStorage;
|
||||
final double overflow = amount - required;
|
||||
@Override
|
||||
public double injectAEPower(final ItemStack is, final double amount, Actionable mode) {
|
||||
final double maxStorage = this.getAEMaxPower(is);
|
||||
final double currentStorage = this.getAECurrentPower(is);
|
||||
final double required = maxStorage - currentStorage;
|
||||
final double overflow = amount - required;
|
||||
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
if (mode == Actionable.MODULATE) {
|
||||
final CompoundNBT data = is.getOrCreateTag();
|
||||
final double toAdd = Math.min( amount, required );
|
||||
final double toAdd = Math.min(amount, required);
|
||||
|
||||
data.putDouble(CURRENT_POWER_NBT_KEY, currentStorage + toAdd);
|
||||
}
|
||||
data.putDouble(CURRENT_POWER_NBT_KEY, currentStorage + toAdd);
|
||||
}
|
||||
|
||||
return Math.max( 0, overflow );
|
||||
}
|
||||
return Math.max(0, overflow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double extractAEPower( final ItemStack is, final double amount, Actionable mode )
|
||||
{
|
||||
final double currentStorage = this.getAECurrentPower( is );
|
||||
final double fulfillable = Math.min( amount, currentStorage );
|
||||
@Override
|
||||
public double extractAEPower(final ItemStack is, final double amount, Actionable mode) {
|
||||
final double currentStorage = this.getAECurrentPower(is);
|
||||
final double fulfillable = Math.min(amount, currentStorage);
|
||||
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
if (mode == Actionable.MODULATE) {
|
||||
final CompoundNBT data = is.getOrCreateTag();
|
||||
|
||||
data.putDouble(CURRENT_POWER_NBT_KEY, currentStorage - fulfillable);
|
||||
}
|
||||
data.putDouble(CURRENT_POWER_NBT_KEY, currentStorage - fulfillable);
|
||||
}
|
||||
|
||||
return fulfillable;
|
||||
}
|
||||
return fulfillable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAEMaxPower( final ItemStack is )
|
||||
{
|
||||
return this.powerCapacity.getAsDouble();
|
||||
}
|
||||
@Override
|
||||
public double getAEMaxPower(final ItemStack is) {
|
||||
return this.powerCapacity.getAsDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAECurrentPower( final ItemStack is )
|
||||
{
|
||||
@Override
|
||||
public double getAECurrentPower(final ItemStack is) {
|
||||
final CompoundNBT data = is.getOrCreateTag();
|
||||
|
||||
return data.getDouble( CURRENT_POWER_NBT_KEY );
|
||||
}
|
||||
return data.getDouble(CURRENT_POWER_NBT_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessRestriction getPowerFlow( final ItemStack is )
|
||||
{
|
||||
return AccessRestriction.WRITE;
|
||||
}
|
||||
@Override
|
||||
public AccessRestriction getPowerFlow(final ItemStack is) {
|
||||
return AccessRestriction.WRITE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities( ItemStack stack, CompoundNBT nbt )
|
||||
{
|
||||
return new PoweredItemCapabilities( stack, this );
|
||||
}
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities(ItemStack stack, CompoundNBT nbt) {
|
||||
return new PoweredItemCapabilities(stack, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.items.tools.powered.powersink;
|
||||
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -33,71 +32,61 @@ import appeng.api.config.PowerUnits;
|
||||
import appeng.api.implementations.items.IAEItemPowerStorage;
|
||||
import appeng.capabilities.Capabilities;
|
||||
|
||||
|
||||
/**
|
||||
* The capability provider to expose chargable items to other mods.
|
||||
*/
|
||||
class PoweredItemCapabilities implements ICapabilityProvider, IEnergyStorage
|
||||
{
|
||||
class PoweredItemCapabilities implements ICapabilityProvider, IEnergyStorage {
|
||||
|
||||
private final ItemStack is;
|
||||
private final ItemStack is;
|
||||
|
||||
private final IAEItemPowerStorage item;
|
||||
private final IAEItemPowerStorage item;
|
||||
|
||||
PoweredItemCapabilities( ItemStack is, IAEItemPowerStorage item )
|
||||
{
|
||||
this.is = is;
|
||||
this.item = item;
|
||||
}
|
||||
PoweredItemCapabilities(ItemStack is, IAEItemPowerStorage item) {
|
||||
this.is = is;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing )
|
||||
{
|
||||
if( capability == Capabilities.FORGE_ENERGY )
|
||||
{
|
||||
return (LazyOptional<T>) LazyOptional.of(() -> this);
|
||||
}
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing) {
|
||||
if (capability == Capabilities.FORGE_ENERGY) {
|
||||
return (LazyOptional<T>) LazyOptional.of(() -> this);
|
||||
}
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy( int maxReceive, boolean simulate )
|
||||
{
|
||||
final double convertedOffer = PowerUnits.RF.convertTo( PowerUnits.AE, maxReceive );
|
||||
final double overflow = this.item.injectAEPower( this.is, convertedOffer, simulate ? Actionable.SIMULATE : Actionable.MODULATE );
|
||||
@Override
|
||||
public int receiveEnergy(int maxReceive, boolean simulate) {
|
||||
final double convertedOffer = PowerUnits.RF.convertTo(PowerUnits.AE, maxReceive);
|
||||
final double overflow = this.item.injectAEPower(this.is, convertedOffer,
|
||||
simulate ? Actionable.SIMULATE : Actionable.MODULATE);
|
||||
|
||||
return maxReceive - (int) PowerUnits.AE.convertTo( PowerUnits.RF, overflow );
|
||||
}
|
||||
return maxReceive - (int) PowerUnits.AE.convertTo(PowerUnits.RF, overflow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy( int maxExtract, boolean simulate )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int extractEnergy(int maxExtract, boolean simulate) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored()
|
||||
{
|
||||
return (int) PowerUnits.AE.convertTo( PowerUnits.RF, this.item.getAECurrentPower( this.is ) );
|
||||
}
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
return (int) PowerUnits.AE.convertTo(PowerUnits.RF, this.item.getAECurrentPower(this.is));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored()
|
||||
{
|
||||
return (int) PowerUnits.AE.convertTo( PowerUnits.RF, this.item.getAEMaxPower( this.is ) );
|
||||
}
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return (int) PowerUnits.AE.convertTo(PowerUnits.RF, this.item.getAEMaxPower(this.is));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtract()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canExtract() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceive()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean canReceive() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user