pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
@@ -18,7 +18,6 @@
package appeng.items.tools;
import java.util.EnumSet;
import java.util.List;
@@ -46,163 +45,132 @@ import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
public class ToolBiometricCard extends AEBaseItem implements IBiometricCard {
public ToolBiometricCard(Properties properties) {
super(properties);
}
public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
{
public ToolBiometricCard(Properties properties) {
super(properties);
}
@Override
public ActionResult<ItemStack> onItemRightClick(final World w, final PlayerEntity p, final Hand hand) {
if (p.isCrouching()) {
this.encode(p.getHeldItem(hand), p);
p.swingArm(hand);
return ActionResult.resultSuccess(p.getHeldItem(hand));
}
@Override
public ActionResult<ItemStack> onItemRightClick( final World w, final PlayerEntity p, final Hand hand )
{
if( p.isCrouching() )
{
this.encode( p.getHeldItem( hand ), p );
p.swingArm( hand );
return ActionResult.resultSuccess( p.getHeldItem( hand ) );
}
return ActionResult.resultPass(p.getHeldItem(hand));
}
return ActionResult.resultPass( p.getHeldItem( hand ) );
}
@Override
public boolean itemInteractionForEntity(ItemStack is, final PlayerEntity player, final LivingEntity target,
final Hand hand) {
if (target instanceof PlayerEntity && !player.isCrouching()) {
if (player.isCreative()) {
is = player.getHeldItem(hand);
}
this.encode(is, (PlayerEntity) target);
player.swingArm(hand);
return true;
}
return false;
}
@Override
public boolean itemInteractionForEntity( ItemStack is, final PlayerEntity player, final LivingEntity target, final Hand hand )
{
if( target instanceof PlayerEntity && !player.isCrouching() )
{
if( player.isCreative() )
{
is = player.getHeldItem( hand );
}
this.encode( is, (PlayerEntity) target );
player.swingArm( hand );
return true;
}
return false;
}
@Override
public ITextComponent getDisplayName(final ItemStack is) {
final GameProfile username = this.getProfile(is);
return username != null ? super.getDisplayName(is).appendText(" - " + username.getName())
: super.getDisplayName(is);
}
@Override
public ITextComponent getDisplayName( final ItemStack is )
{
final GameProfile username = this.getProfile( is );
return username != null ? super.getDisplayName( is ).appendText( " - " + username.getName() ) : super.getDisplayName( is );
}
private void encode(final ItemStack is, final PlayerEntity p) {
final GameProfile username = this.getProfile(is);
private void encode( final ItemStack is, final PlayerEntity p )
{
final GameProfile username = this.getProfile( is );
if (username != null && username.equals(p.getGameProfile())) {
this.setProfile(is, null);
} else {
this.setProfile(is, p.getGameProfile());
}
}
if( username != null && username.equals( p.getGameProfile() ) )
{
this.setProfile( is, null );
}
else
{
this.setProfile( is, p.getGameProfile() );
}
}
@Override
public void setProfile(final ItemStack itemStack, final GameProfile profile) {
final CompoundNBT tag = itemStack.getOrCreateTag();
@Override
public void setProfile( final ItemStack itemStack, final GameProfile profile )
{
final CompoundNBT tag = itemStack.getOrCreateTag();
if (profile != null) {
final CompoundNBT pNBT = new CompoundNBT();
NBTUtil.writeGameProfile(pNBT, profile);
tag.put("profile", pNBT);
} else {
tag.remove("profile");
}
}
if( profile != null )
{
final CompoundNBT pNBT = new CompoundNBT();
NBTUtil.writeGameProfile( pNBT, profile );
tag.put( "profile", pNBT );
}
else
{
tag.remove( "profile" );
}
}
@Override
public GameProfile getProfile(final ItemStack is) {
final CompoundNBT tag = is.getOrCreateTag();
if (tag.contains("profile")) {
return NBTUtil.readGameProfile(tag.getCompound("profile"));
}
return null;
}
@Override
public GameProfile getProfile( final ItemStack is )
{
final CompoundNBT tag = is.getOrCreateTag();
if( tag.contains( "profile" ) )
{
return NBTUtil.readGameProfile( tag.getCompound( "profile" ) );
}
return null;
}
@Override
public EnumSet<SecurityPermissions> getPermissions(final ItemStack is) {
final CompoundNBT tag = is.getOrCreateTag();
final EnumSet<SecurityPermissions> result = EnumSet.noneOf(SecurityPermissions.class);
@Override
public EnumSet<SecurityPermissions> getPermissions( final ItemStack is )
{
final CompoundNBT tag = is.getOrCreateTag();
final EnumSet<SecurityPermissions> result = EnumSet.noneOf( SecurityPermissions.class );
for (final SecurityPermissions sp : SecurityPermissions.values()) {
if (tag.getBoolean(sp.name())) {
result.add(sp);
}
}
for( final SecurityPermissions sp : SecurityPermissions.values() )
{
if( tag.getBoolean( sp.name() ) )
{
result.add( sp );
}
}
return result;
}
return result;
}
@Override
public boolean hasPermission(final ItemStack is, final SecurityPermissions permission) {
final CompoundNBT tag = is.getOrCreateTag();
return tag.getBoolean(permission.name());
}
@Override
public boolean hasPermission( final ItemStack is, final SecurityPermissions permission )
{
final CompoundNBT tag = is.getOrCreateTag();
return tag.getBoolean( permission.name() );
}
@Override
public void removePermission(final ItemStack itemStack, final SecurityPermissions permission) {
final CompoundNBT tag = itemStack.getOrCreateTag();
if (tag.contains(permission.name())) {
tag.remove(permission.name());
}
}
@Override
public void removePermission( final ItemStack itemStack, final SecurityPermissions permission )
{
final CompoundNBT tag = itemStack.getOrCreateTag();
if( tag.contains( permission.name() ) )
{
tag.remove( permission.name() );
}
}
@Override
public void addPermission(final ItemStack itemStack, final SecurityPermissions permission) {
final CompoundNBT tag = itemStack.getOrCreateTag();
tag.putBoolean(permission.name(), true);
}
@Override
public void addPermission( final ItemStack itemStack, final SecurityPermissions permission )
{
final CompoundNBT tag = itemStack.getOrCreateTag();
tag.putBoolean( permission.name(), true );
}
@Override
public void registerPermissions(final ISecurityRegistry register, final IPlayerRegistry pr, final ItemStack is) {
register.addPlayer(pr.getID(this.getProfile(is)), this.getPermissions(is));
}
@Override
public void registerPermissions( final ISecurityRegistry register, final IPlayerRegistry pr, final ItemStack is )
{
register.addPlayer( pr.getID( this.getProfile( is ) ), this.getPermissions( is ) );
}
@Override
@OnlyIn(Dist.CLIENT)
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines,
final ITooltipFlag advancedTooltips) {
final EnumSet<SecurityPermissions> perms = this.getPermissions(stack);
if (perms.isEmpty()) {
lines.add(new TranslationTextComponent(GuiText.NoPermissions.getLocal()));
} else {
ITextComponent msg = null;
@Override
@OnlyIn( Dist.CLIENT )
public void addInformation( final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
{
final EnumSet<SecurityPermissions> perms = this.getPermissions( stack );
if( perms.isEmpty() )
{
lines.add( new TranslationTextComponent( GuiText.NoPermissions.getLocal() ) );
}
else
{
ITextComponent msg = null;
for( final SecurityPermissions sp : perms )
{
if( msg == null )
{
msg = new TranslationTextComponent( sp.getTranslatedName() );
}
else
{
msg = msg.appendText( ", " ).appendSibling( new TranslationTextComponent( sp.getTranslatedName() ) );
}
}
lines.add( msg );
}
}
for (final SecurityPermissions sp : perms) {
if (msg == null) {
msg = new TranslationTextComponent(sp.getTranslatedName());
} else {
msg = msg.appendText(", ").appendSibling(new TranslationTextComponent(sp.getTranslatedName()));
}
}
lines.add(msg);
}
}
}
@@ -18,7 +18,6 @@
package appeng.items.tools;
import java.util.List;
import net.minecraft.client.resources.I18n;
@@ -47,192 +46,154 @@ import appeng.core.localization.PlayerMessages;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
public class ToolMemoryCard extends AEBaseItem implements IMemoryCard {
public class ToolMemoryCard extends AEBaseItem implements IMemoryCard
{
private static final AEColor[] DEFAULT_COLOR_CODE = new AEColor[] { AEColor.TRANSPARENT, AEColor.TRANSPARENT,
AEColor.TRANSPARENT, AEColor.TRANSPARENT, AEColor.TRANSPARENT, AEColor.TRANSPARENT, AEColor.TRANSPARENT,
AEColor.TRANSPARENT, };
private static final AEColor[] DEFAULT_COLOR_CODE = new AEColor[] {
AEColor.TRANSPARENT,
AEColor.TRANSPARENT,
AEColor.TRANSPARENT,
AEColor.TRANSPARENT,
AEColor.TRANSPARENT,
AEColor.TRANSPARENT,
AEColor.TRANSPARENT,
AEColor.TRANSPARENT,
};
public ToolMemoryCard(Properties properties) {
super(properties);
}
public ToolMemoryCard(Properties properties) {
super(properties);
}
@Override
@OnlyIn(Dist.CLIENT)
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines,
final ITooltipFlag advancedTooltips) {
String firstLineKey = this.getFirstValidTranslationKey(this.getSettingsName(stack) + ".name",
this.getSettingsName(stack));
lines.add(new TranslationTextComponent(firstLineKey));
@Override
@OnlyIn( Dist.CLIENT )
public void addInformation( final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
{
String firstLineKey = this.getFirstValidTranslationKey( this.getSettingsName( stack ) + ".name", this.getSettingsName( stack ) );
lines.add( new TranslationTextComponent(firstLineKey));
final CompoundNBT data = this.getData(stack);
if (data.contains("tooltip")) {
String tooltipKey = getFirstValidTranslationKey(data.getString("tooltip") + ".name",
data.getString("tooltip"));
lines.add(new TranslationTextComponent(tooltipKey));
}
final CompoundNBT data = this.getData( stack );
if( data.contains( "tooltip" ) )
{
String tooltipKey = getFirstValidTranslationKey( data.getString( "tooltip" ) + ".name", data.getString( "tooltip" ) );
lines.add( new TranslationTextComponent(tooltipKey) );
}
if (data.contains("freq")) {
final short freq = data.getShort("freq");
final String freqTooltip = TextFormatting.BOLD + Platform.p2p().toHexString(freq);
if( data.contains( "freq" ) )
{
final short freq = data.getShort( "freq" );
final String freqTooltip = TextFormatting.BOLD + Platform.p2p().toHexString( freq );
lines.add(new TranslationTextComponent("gui.tooltips.appliedenergistics2.P2PFrequency", freqTooltip));
}
}
lines.add( new TranslationTextComponent( "gui.tooltips.appliedenergistics2.P2PFrequency", freqTooltip ) );
}
}
/**
* Find the localized string...
*
* @param name possible names for the localized string
*
* @return localized name
*/
private String getFirstValidTranslationKey(final String... name) {
for (final String n : name) {
if (I18n.hasKey(n)) {
return n;
}
}
/**
* Find the localized string...
*
* @param name possible names for the localized string
*
* @return localized name
*/
private String getFirstValidTranslationKey( final String... name )
{
for( final String n : name )
{
if( I18n.hasKey(n) )
{
return n;
}
}
for (final String n : name) {
return n;
}
for( final String n : name )
{
return n;
}
return "";
}
return "";
}
@Override
public void setMemoryCardContents(final ItemStack is, final String settingsName, final CompoundNBT data) {
final CompoundNBT c = is.getOrCreateTag();
c.putString("Config", settingsName);
c.put("Data", data);
}
@Override
public void setMemoryCardContents( final ItemStack is, final String settingsName, final CompoundNBT data )
{
final CompoundNBT c = is.getOrCreateTag();
c.putString( "Config", settingsName );
c.put( "Data", data );
}
@Override
public String getSettingsName(final ItemStack is) {
final CompoundNBT c = is.getOrCreateTag();
final String name = c.getString("Config");
return name.isEmpty() ? GuiText.Blank.getTranslationKey() : name;
}
@Override
public String getSettingsName( final ItemStack is )
{
final CompoundNBT c = is.getOrCreateTag();
final String name = c.getString( "Config" );
return name.isEmpty() ? GuiText.Blank.getTranslationKey() : name;
}
@Override
public CompoundNBT getData(final ItemStack is) {
final CompoundNBT c = is.getOrCreateTag();
CompoundNBT o = c.getCompound("Data");
return o.copy();
}
@Override
public CompoundNBT getData( final ItemStack is )
{
final CompoundNBT c = is.getOrCreateTag();
CompoundNBT o = c.getCompound( "Data" );
return o.copy();
}
@Override
public AEColor[] getColorCode(ItemStack is) {
final CompoundNBT tag = this.getData(is);
@Override
public AEColor[] getColorCode( ItemStack is )
{
final CompoundNBT tag = this.getData( is );
if (tag.contains("colorCode")) {
final int[] frequency = tag.getIntArray("colorCode");
final AEColor[] colorArray = AEColor.values();
if( tag.contains( "colorCode" ) )
{
final int[] frequency = tag.getIntArray( "colorCode" );
final AEColor[] colorArray = AEColor.values();
return new AEColor[] { colorArray[frequency[0]], colorArray[frequency[1]], colorArray[frequency[2]],
colorArray[frequency[3]], colorArray[frequency[4]], colorArray[frequency[5]],
colorArray[frequency[6]], colorArray[frequency[7]], };
}
return new AEColor[] {
colorArray[frequency[0]],
colorArray[frequency[1]],
colorArray[frequency[2]],
colorArray[frequency[3]],
colorArray[frequency[4]],
colorArray[frequency[5]],
colorArray[frequency[6]],
colorArray[frequency[7]],
};
}
return DEFAULT_COLOR_CODE;
}
return DEFAULT_COLOR_CODE;
}
@Override
public void notifyUser(final PlayerEntity player, final MemoryCardMessages msg) {
if (Platform.isClient()) {
return;
}
@Override
public void notifyUser( final PlayerEntity player, final MemoryCardMessages msg )
{
if( Platform.isClient() )
{
return;
}
switch (msg) {
case SETTINGS_CLEARED:
player.sendMessage(PlayerMessages.SettingCleared.get());
break;
case INVALID_MACHINE:
player.sendMessage(PlayerMessages.InvalidMachine.get());
break;
case SETTINGS_LOADED:
player.sendMessage(PlayerMessages.LoadedSettings.get());
break;
case SETTINGS_SAVED:
player.sendMessage(PlayerMessages.SavedSettings.get());
break;
case SETTINGS_RESET:
player.sendMessage(PlayerMessages.ResetSettings.get());
break;
default:
}
}
switch( msg )
{
case SETTINGS_CLEARED:
player.sendMessage( PlayerMessages.SettingCleared.get() );
break;
case INVALID_MACHINE:
player.sendMessage( PlayerMessages.InvalidMachine.get() );
break;
case SETTINGS_LOADED:
player.sendMessage( PlayerMessages.LoadedSettings.get() );
break;
case SETTINGS_SAVED:
player.sendMessage( PlayerMessages.SavedSettings.get() );
break;
case SETTINGS_RESET:
player.sendMessage( PlayerMessages.ResetSettings.get() );
break;
default:
}
}
@Override
public ActionResultType onItemUse(ItemUseContext context) {
if (context.getPlayer().isCrouching()) {
if (!context.getPlayer().world.isRemote) {
this.clearCard(context.getPlayer(), context.getWorld(), context.getHand());
}
return ActionResultType.SUCCESS;
} else {
return super.onItemUse(context);
}
}
@Override
public ActionResultType onItemUse( ItemUseContext context )
{
if( context.getPlayer().isCrouching() )
{
if( !context.getPlayer().world.isRemote )
{
this.clearCard( context.getPlayer(), context.getWorld(), context.getHand() );
}
return ActionResultType.SUCCESS;
}
else
{
return super.onItemUse( context );
}
}
@Override
public ActionResult<ItemStack> onItemRightClick(World w, PlayerEntity player, Hand hand) {
if (player.isCrouching()) {
if (!w.isRemote) {
this.clearCard(player, w, hand);
}
}
@Override
public ActionResult<ItemStack> onItemRightClick( World w, PlayerEntity player, Hand hand )
{
if( player.isCrouching() )
{
if( !w.isRemote )
{
this.clearCard( player, w, hand );
}
}
return super.onItemRightClick(w, player, hand);
}
return super.onItemRightClick( w, player, hand );
}
@Override
public boolean doesSneakBypassUse(ItemStack stack, IWorldReader world, BlockPos pos, PlayerEntity player) {
return true;
}
@Override
public boolean doesSneakBypassUse( ItemStack stack, IWorldReader world, BlockPos pos, PlayerEntity player )
{
return true;
}
private void clearCard( final PlayerEntity player, final World w, final Hand hand )
{
final IMemoryCard mem = (IMemoryCard) player.getHeldItem( hand ).getItem();
mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED );
player.getHeldItem( hand ).setTag( null );
}
private void clearCard(final PlayerEntity player, final World w, final Hand hand) {
final IMemoryCard mem = (IMemoryCard) player.getHeldItem(hand).getItem();
mem.notifyUser(player, MemoryCardMessages.SETTINGS_CLEARED);
player.getHeldItem(hand).setTag(null);
}
}
@@ -18,11 +18,6 @@
package appeng.items.tools;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.ContainerNetworkStatus;
import appeng.container.implementations.ContainerNetworkTool;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
@@ -50,149 +45,126 @@ import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.api.util.INetworkToolAgent;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.ContainerNetworkStatus;
import appeng.container.implementations.ContainerNetworkTool;
import appeng.core.AppEng;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketClick;
import appeng.items.AEBaseItem;
import appeng.items.contents.NetworkToolViewer;
import appeng.util.Platform;
public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench {
public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench
{
public ToolNetworkTool(Properties properties) {
super(properties);
}
public ToolNetworkTool(Properties properties) {
super(properties);
}
@Override
public IGuiItemObject getGuiObject(final ItemStack is, int playerInventorySlot, final World world,
final BlockPos pos) {
if (pos == null) {
return new NetworkToolViewer(is, null);
}
final TileEntity te = world.getTileEntity(pos);
return new NetworkToolViewer(is, (IGridHost) (te instanceof IGridHost ? te : null));
}
@Override
public IGuiItemObject getGuiObject( final ItemStack is, int playerInventorySlot, final World world, final BlockPos pos )
{
if (pos == null) {
return new NetworkToolViewer( is, null );
}
final TileEntity te = world.getTileEntity( pos );
return new NetworkToolViewer( is, (IGridHost) ( te instanceof IGridHost ? te : null ) );
}
@Override
public ActionResult<ItemStack> onItemRightClick(final World w, final PlayerEntity p, final Hand hand) {
if (Platform.isClient()) {
final RayTraceResult mop = AppEng.proxy.getRTR();
@Override
public ActionResult<ItemStack> onItemRightClick( final World w, final PlayerEntity p, final Hand hand )
{
if( Platform.isClient() )
{
final RayTraceResult mop = AppEng.proxy.getRTR();
if (mop == null || mop.getType() == RayTraceResult.Type.MISS) {
NetworkHandler.instance().sendToServer(new PacketClick(hand));
}
}
if( mop == null || mop.getType() == RayTraceResult.Type.MISS )
{
NetworkHandler.instance().sendToServer( new PacketClick( hand ) );
}
}
return new ActionResult<>(ActionResultType.SUCCESS, p.getHeldItem(hand));
}
return new ActionResult<>( ActionResultType.SUCCESS, p.getHeldItem( hand ) );
}
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
final BlockRayTraceResult mop = new BlockRayTraceResult(context.getHitVec(), context.getFace(),
context.getPos(), context.isInside());
final TileEntity te = context.getWorld().getTileEntity(context.getPos());
@Override
public ActionResultType onItemUseFirst( ItemStack stack, ItemUseContext context )
{
final BlockRayTraceResult mop = new BlockRayTraceResult( context.getHitVec(), context.getFace(), context.getPos(), context.isInside() );
final TileEntity te = context.getWorld().getTileEntity( context.getPos() );
if (te instanceof IPartHost) {
final SelectedPart part = ((IPartHost) te).selectPart(mop.getHitVec());
if( te instanceof IPartHost )
{
final SelectedPart part = ( (IPartHost) te ).selectPart( mop.getHitVec() );
if (part.part != null || part.facade != null) {
if (part.part instanceof INetworkToolAgent && !((INetworkToolAgent) part.part).showNetworkInfo(mop)) {
return ActionResultType.FAIL;
} else if (context.getPlayer().isCrouching()) {
return ActionResultType.PASS;
}
}
} else if (te instanceof INetworkToolAgent && !((INetworkToolAgent) te).showNetworkInfo(mop)) {
return ActionResultType.FAIL;
}
if( part.part != null || part.facade != null )
{
if( part.part instanceof INetworkToolAgent && !( (INetworkToolAgent) part.part ).showNetworkInfo( mop ) )
{
return ActionResultType.FAIL;
}
else if( context.getPlayer().isCrouching() )
{
return ActionResultType.PASS;
}
}
}
else if( te instanceof INetworkToolAgent && !( (INetworkToolAgent) te ).showNetworkInfo( mop ) )
{
return ActionResultType.FAIL;
}
if (Platform.isClient()) {
NetworkHandler.instance().sendToServer(new PacketClick(context));
}
if( Platform.isClient() )
{
NetworkHandler.instance().sendToServer( new PacketClick( context ) );
}
return ActionResultType.SUCCESS;
}
return ActionResultType.SUCCESS;
}
@Override
public boolean doesSneakBypassUse(ItemStack stack, IWorldReader world, BlockPos pos, PlayerEntity player) {
return true;
}
@Override
public boolean doesSneakBypassUse( ItemStack stack, IWorldReader world, BlockPos pos, PlayerEntity player )
{
return true;
}
public boolean serverSideToolLogic(ItemUseContext useContext) {
BlockPos pos = useContext.getPos();
PlayerEntity p = useContext.getPlayer();
World w = p.world;
Hand hand = useContext.getHand();
Direction side = useContext.getFace();
public boolean serverSideToolLogic( ItemUseContext useContext )
{
BlockPos pos = useContext.getPos();
PlayerEntity p = useContext.getPlayer();
World w = p.world;
Hand hand = useContext.getHand();
Direction side = useContext.getFace();
if (!Platform.hasPermissions(new DimensionalCoord(w, pos), p)) {
return false;
}
if( !Platform.hasPermissions( new DimensionalCoord( w, pos ), p ) )
{
return false;
}
final BlockState bs = w.getBlockState(pos);
if (!p.isCrouching()) {
final TileEntity te = w.getTileEntity(pos);
if (!(te instanceof IGridHost)) {
if (bs.rotate(w, pos, Rotation.CLOCKWISE_90) != bs) {
bs.neighborChanged(w, pos, Platform.AIR_BLOCK, pos, false);
p.swingArm(hand);
return !w.isRemote;
}
}
}
final BlockState bs = w.getBlockState( pos );
if( !p.isCrouching() )
{
final TileEntity te = w.getTileEntity( pos );
if( !( te instanceof IGridHost ) )
{
if( bs.rotate( w, pos, Rotation.CLOCKWISE_90 ) != bs )
{
bs.neighborChanged( w, pos, Platform.AIR_BLOCK, pos, false );
p.swingArm( hand );
return !w.isRemote;
}
}
}
if (!p.isCrouching()) {
if (p.openContainer instanceof AEBaseContainer) {
return true;
}
if( !p.isCrouching() )
{
if( p.openContainer instanceof AEBaseContainer )
{
return true;
}
final TileEntity te = w.getTileEntity(pos);
final TileEntity te = w.getTileEntity( pos );
if (te instanceof IGridHost) {
ContainerOpener.openContainer(ContainerNetworkStatus.TYPE, p,
ContainerLocator.forItemUseContext(useContext));
} else {
ContainerOpener.openContainer(ContainerNetworkTool.TYPE, p, ContainerLocator.forHand(p, hand));
}
if( te instanceof IGridHost )
{
ContainerOpener.openContainer(ContainerNetworkStatus.TYPE, p, ContainerLocator.forItemUseContext(useContext));
}
else
{
ContainerOpener.openContainer(ContainerNetworkTool.TYPE, p, ContainerLocator.forHand(p, hand));
}
return true;
} else {
BlockRayTraceResult rtr = new BlockRayTraceResult(useContext.getHitVec(), side, pos, false);
bs.onBlockActivated(w, p, hand, rtr);
}
return true;
}
else
{
BlockRayTraceResult rtr = new BlockRayTraceResult(useContext.getHitVec(), side, pos, false);
bs.onBlockActivated( w, p, hand, rtr );
}
return false;
}
return false;
}
@Override
public boolean canWrench( final ItemStack wrench, final PlayerEntity player, final BlockPos pos )
{
return true;
}
@Override
public boolean canWrench(final ItemStack wrench, final PlayerEntity player, final BlockPos pos) {
return true;
}
}
@@ -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;
}
}
@@ -18,7 +18,6 @@
package appeng.items.tools.quartz;
import net.minecraft.item.AxeItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
@@ -28,20 +27,16 @@ import net.minecraft.item.ItemTier;
import appeng.api.features.AEFeature;
import appeng.util.Platform;
public class ToolQuartzAxe extends AxeItem {
private final AEFeature type;
public class ToolQuartzAxe extends AxeItem
{
private final AEFeature type;
public ToolQuartzAxe(Item.Properties props, final AEFeature type) {
super(ItemTier.IRON, 6.0F, -3.1F, props);
this.type = type;
}
public ToolQuartzAxe( Item.Properties props, final AEFeature type )
{
super( ItemTier.IRON, 6.0F, -3.1F, props );
this.type = type;
}
@Override
public boolean getIsRepairable( final ItemStack a, final ItemStack b )
{
return Platform.canRepair( this.type, a, b );
}
@Override
public boolean getIsRepairable(final ItemStack a, final ItemStack b) {
return Platform.canRepair(this.type, a, b);
}
}
@@ -18,16 +18,6 @@
package appeng.items.tools.quartz;
import appeng.api.features.AEFeature;
import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.ContainerQuartzKnife;
import appeng.items.AEBaseItem;
import appeng.items.contents.QuartzKnifeObj;
import appeng.util.Platform;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -38,63 +28,64 @@ import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import appeng.api.features.AEFeature;
import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.ContainerQuartzKnife;
import appeng.items.AEBaseItem;
import appeng.items.contents.QuartzKnifeObj;
import appeng.util.Platform;
public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem
{
private final AEFeature type;
public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem {
private final AEFeature type;
public ToolQuartzCuttingKnife( Item.Properties props, final AEFeature type )
{
super(props);
this.type = type;
}
public ToolQuartzCuttingKnife(Item.Properties props, final AEFeature type) {
super(props);
this.type = type;
}
@Override
public ActionResultType onItemUse(ItemUseContext context )
{
PlayerEntity player = context.getPlayer();
if( Platform.isServer() && player != null )
{
ContainerOpener.openContainer(ContainerQuartzKnife.TYPE, context.getPlayer(), ContainerLocator.forItemUseContext(context));
}
return ActionResultType.SUCCESS;
}
@Override
public ActionResultType onItemUse(ItemUseContext context) {
PlayerEntity player = context.getPlayer();
if (Platform.isServer() && player != null) {
ContainerOpener.openContainer(ContainerQuartzKnife.TYPE, context.getPlayer(),
ContainerLocator.forItemUseContext(context));
}
return ActionResultType.SUCCESS;
}
@Override
public ActionResult<ItemStack> onItemRightClick( final World w, final PlayerEntity p, final Hand hand )
{
if( Platform.isServer() )
{
ContainerOpener.openContainer(ContainerQuartzKnife.TYPE, p, ContainerLocator.forHand(p, hand));
}
p.swingArm( hand );
return new ActionResult<>( ActionResultType.SUCCESS, p.getHeldItem( hand ) );
}
@Override
public ActionResult<ItemStack> onItemRightClick(final World w, final PlayerEntity p, final Hand hand) {
if (Platform.isServer()) {
ContainerOpener.openContainer(ContainerQuartzKnife.TYPE, p, ContainerLocator.forHand(p, hand));
}
p.swingArm(hand);
return new ActionResult<>(ActionResultType.SUCCESS, p.getHeldItem(hand));
}
@Override
public boolean getIsRepairable( final ItemStack a, final ItemStack b )
{
return Platform.canRepair( this.type, a, b );
}
@Override
public boolean getIsRepairable(final ItemStack a, final ItemStack b) {
return Platform.canRepair(this.type, a, b);
}
@Override
public ItemStack getContainerItem( final ItemStack itemStack )
{
ItemStack copy = itemStack.copy();
copy.setDamage( itemStack.getDamage() + 1 );
@Override
public ItemStack getContainerItem(final ItemStack itemStack) {
ItemStack copy = itemStack.copy();
copy.setDamage(itemStack.getDamage() + 1);
return copy;
}
return copy;
}
@Override
public boolean hasContainerItem( final ItemStack stack )
{
return true;
}
@Override
public boolean hasContainerItem(final ItemStack stack) {
return true;
}
@Override
public IGuiItemObject getGuiObject( final ItemStack is, int playerInventorySlot, final World world, final BlockPos pos )
{
return new QuartzKnifeObj( is );
}
@Override
public IGuiItemObject getGuiObject(final ItemStack is, int playerInventorySlot, final World world,
final BlockPos pos) {
return new QuartzKnifeObj(is);
}
}
@@ -18,7 +18,6 @@
package appeng.items.tools.quartz;
import net.minecraft.item.HoeItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
@@ -28,21 +27,17 @@ import net.minecraft.item.ItemTier;
import appeng.api.features.AEFeature;
import appeng.util.Platform;
public class ToolQuartzHoe extends HoeItem {
private final AEFeature type;
public class ToolQuartzHoe extends HoeItem
{
private final AEFeature type;
public ToolQuartzHoe(Item.Properties props, final AEFeature type) {
super(ItemTier.IRON, -1.0F, props);
this.type = type;
}
public ToolQuartzHoe( Item.Properties props, final AEFeature type )
{
super( ItemTier.IRON, -1.0F, props);
this.type = type;
}
@Override
public boolean getIsRepairable( final ItemStack a, final ItemStack b )
{
return Platform.canRepair( this.type, a, b );
}
@Override
public boolean getIsRepairable(final ItemStack a, final ItemStack b) {
return Platform.canRepair(this.type, a, b);
}
}
@@ -18,7 +18,6 @@
package appeng.items.tools.quartz;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
@@ -28,20 +27,16 @@ import net.minecraft.item.PickaxeItem;
import appeng.api.features.AEFeature;
import appeng.util.Platform;
public class ToolQuartzPickaxe extends PickaxeItem {
private final AEFeature type;
public class ToolQuartzPickaxe extends PickaxeItem
{
private final AEFeature type;
public ToolQuartzPickaxe(Item.Properties props, final AEFeature type) {
super(ItemTier.IRON, 1, -2.8F, props);
this.type = type;
}
public ToolQuartzPickaxe( Item.Properties props, final AEFeature type )
{
super( ItemTier.IRON, 1, -2.8F, props );
this.type = type;
}
@Override
public boolean getIsRepairable( final ItemStack a, final ItemStack b )
{
return Platform.canRepair( this.type, a, b );
}
@Override
public boolean getIsRepairable(final ItemStack a, final ItemStack b) {
return Platform.canRepair(this.type, a, b);
}
}
@@ -18,7 +18,6 @@
package appeng.items.tools.quartz;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
@@ -28,20 +27,16 @@ import net.minecraft.item.ShovelItem;
import appeng.api.features.AEFeature;
import appeng.util.Platform;
public class ToolQuartzSpade extends ShovelItem {
private final AEFeature type;
public class ToolQuartzSpade extends ShovelItem
{
private final AEFeature type;
public ToolQuartzSpade(Item.Properties props, final AEFeature type) {
super(ItemTier.IRON, 1.5F, -3.0F, props);
this.type = type;
}
public ToolQuartzSpade( Item.Properties props, final AEFeature type )
{
super( ItemTier.IRON, 1.5F, -3.0F, props );
this.type = type;
}
@Override
public boolean getIsRepairable( final ItemStack a, final ItemStack b )
{
return Platform.canRepair( this.type, a, b );
}
@Override
public boolean getIsRepairable(final ItemStack a, final ItemStack b) {
return Platform.canRepair(this.type, a, b);
}
}
@@ -18,7 +18,6 @@
package appeng.items.tools.quartz;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
@@ -28,20 +27,16 @@ import net.minecraft.item.SwordItem;
import appeng.api.features.AEFeature;
import appeng.util.Platform;
public class ToolQuartzSword extends SwordItem {
private final AEFeature type;
public class ToolQuartzSword extends SwordItem
{
private final AEFeature type;
public ToolQuartzSword(Item.Properties props, AEFeature type) {
super(ItemTier.IRON, 3, -2.4F, props);
this.type = type;
}
public ToolQuartzSword( Item.Properties props, AEFeature type )
{
super( ItemTier.IRON, 3, -2.4F, props );
this.type = type;
}
@Override
public boolean getIsRepairable( final ItemStack a, final ItemStack b )
{
return Platform.canRepair( this.type, a, b );
}
@Override
public boolean getIsRepairable(final ItemStack a, final ItemStack b) {
return Platform.canRepair(this.type, a, b);
}
}
@@ -18,12 +18,6 @@
package appeng.items.tools.quartz;
import appeng.api.implementations.items.IAEWrench;
import appeng.api.util.DimensionalCoord;
import appeng.block.AEBaseBlock;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import net.minecraft.block.Block;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
@@ -32,42 +26,43 @@ import net.minecraft.item.ItemUseContext;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.math.BlockPos;
import appeng.api.implementations.items.IAEWrench;
import appeng.api.util.DimensionalCoord;
import appeng.block.AEBaseBlock;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
public class ToolQuartzWrench extends AEBaseItem implements IAEWrench
{
public class ToolQuartzWrench extends AEBaseItem implements IAEWrench {
public ToolQuartzWrench(Item.Properties props)
{
super( props );
}
public ToolQuartzWrench(Item.Properties props) {
super(props);
}
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
if( !context.getPlayer().isCrouching() && Platform.hasPermissions( new DimensionalCoord( context.getWorld(), context.getPos() ),
context.getPlayer() ) )
{
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
if (!context.getPlayer().isCrouching() && Platform
.hasPermissions(new DimensionalCoord(context.getWorld(), context.getPos()), context.getPlayer())) {
Block block = context.getWorld().getBlockState(context.getPos()).getBlock();
if (block instanceof AEBaseBlock) {
if( Platform.isClient() )
{
// TODO 1.10-R - if we return FAIL on client, action will not be sent to server. Fix that in all Block#onItemUseFirst overrides.
return !context.getWorld().isRemote ? ActionResultType.SUCCESS : ActionResultType.PASS;
}
Block block = context.getWorld().getBlockState(context.getPos()).getBlock();
if (block instanceof AEBaseBlock) {
if (Platform.isClient()) {
// TODO 1.10-R - if we return FAIL on client, action will not be sent to server.
// Fix that in all Block#onItemUseFirst overrides.
return !context.getWorld().isRemote ? ActionResultType.SUCCESS : ActionResultType.PASS;
}
AEBaseBlock aeBlock = (AEBaseBlock) block;
if (aeBlock.rotateAroundFaceAxis(context.getWorld(), context.getPos(), context.getFace())) {
context.getPlayer().swingArm(context.getHand());
return !context.getWorld().isRemote ? ActionResultType.SUCCESS : ActionResultType.FAIL;
}
}
}
return ActionResultType.PASS;
}
AEBaseBlock aeBlock = (AEBaseBlock) block;
if (aeBlock.rotateAroundFaceAxis(context.getWorld(), context.getPos(), context.getFace())) {
context.getPlayer().swingArm(context.getHand());
return !context.getWorld().isRemote ? ActionResultType.SUCCESS : ActionResultType.FAIL;
}
}
}
return ActionResultType.PASS;
}
@Override
public boolean canWrench( final ItemStack wrench, final PlayerEntity player, final BlockPos pos )
{
return true;
}
@Override
public boolean canWrench(final ItemStack wrench, final PlayerEntity player, final BlockPos pos) {
return true;
}
}