Rewrite IBindable to provide an object instead of storing 2 strings
This commit is contained in:
parent
941173dbf4
commit
2a43e53842
47 changed files with 416 additions and 510 deletions
|
@ -51,7 +51,7 @@ public class ItemSigilAir extends ItemSigilBase implements ISentientSwordEffectP
|
|||
|
||||
if (!world.isRemote) {
|
||||
if (!player.capabilities.isCreativeMode)
|
||||
this.setUnusable(stack, !NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed()));
|
||||
this.setUnusable(stack, !NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, getLpUsed()));
|
||||
|
||||
if (!unusable)
|
||||
player.fallDistance = 0;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package WayofTime.bloodmagic.item.sigil;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.core.data.Binding;
|
||||
import WayofTime.bloodmagic.item.ItemSigil;
|
||||
import WayofTime.bloodmagic.util.helper.PlayerHelper;
|
||||
import WayofTime.bloodmagic.client.IVariantProvider;
|
||||
|
@ -18,6 +19,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
public class ItemSigilBase extends ItemSigil implements IVariantProvider {
|
||||
|
||||
protected final String tooltipBase;
|
||||
private final String name;
|
||||
|
||||
|
@ -44,8 +46,9 @@ public class ItemSigilBase extends ItemSigil implements IVariantProvider {
|
|||
if (!stack.hasTagCompound())
|
||||
return;
|
||||
|
||||
if (!Strings.isNullOrEmpty(getOwnerName(stack)))
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", PlayerHelper.getUsernameFromStack(stack)));
|
||||
Binding binding = getBinding(stack);
|
||||
if (binding != null)
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName()));
|
||||
|
||||
super.addInformation(stack, world, tooltip, flag);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package WayofTime.bloodmagic.item.sigil;
|
||||
|
||||
import WayofTime.bloodmagic.core.data.SoulNetwork;
|
||||
import WayofTime.bloodmagic.util.Constants;
|
||||
import WayofTime.bloodmagic.iface.ISigil;
|
||||
import WayofTime.bloodmagic.util.helper.NBTHelper;
|
||||
|
@ -41,13 +42,14 @@ public class ItemSigilBloodLight extends ItemSigilBase {
|
|||
if (getCooldownRemainder(stack) > 0)
|
||||
return super.onItemRightClick(world, player, hand);
|
||||
|
||||
SoulNetwork network = NetworkHelper.getSoulNetwork(getBinding(stack));
|
||||
if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK) {
|
||||
BlockPos blockPos = mop.getBlockPos().offset(mop.sideHit);
|
||||
|
||||
if (world.isAirBlock(blockPos)) {
|
||||
world.setBlockState(blockPos, RegistrarBloodMagicBlocks.BLOOD_LIGHT.getDefaultState());
|
||||
if (!world.isRemote)
|
||||
NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed());
|
||||
network.syphonAndDamage(player, getLpUsed());
|
||||
resetCooldown(stack);
|
||||
player.swingArm(hand);
|
||||
return super.onItemRightClick(world, player, hand);
|
||||
|
@ -55,7 +57,7 @@ public class ItemSigilBloodLight extends ItemSigilBase {
|
|||
} else {
|
||||
if (!world.isRemote) {
|
||||
world.spawnEntity(new EntityBloodLight(world, player));
|
||||
NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed());
|
||||
network.syphonAndDamage(player, getLpUsed());
|
||||
}
|
||||
resetCooldown(stack);
|
||||
}
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
package WayofTime.bloodmagic.item.sigil;
|
||||
|
||||
import WayofTime.bloodmagic.core.data.Binding;
|
||||
import WayofTime.bloodmagic.iface.IAltarReader;
|
||||
import WayofTime.bloodmagic.iface.ISigil;
|
||||
import WayofTime.bloodmagic.util.helper.NetworkHelper;
|
||||
import WayofTime.bloodmagic.util.helper.PlayerHelper;
|
||||
import WayofTime.bloodmagic.util.ChatUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemSigilDivination extends ItemSigilBase implements IAltarReader {
|
||||
|
@ -35,13 +35,12 @@ public class ItemSigilDivination extends ItemSigilBase implements IAltarReader {
|
|||
if (!world.isRemote) {
|
||||
super.onItemRightClick(world, player, hand);
|
||||
|
||||
RayTraceResult rayTrace = rayTrace(world, player, false);
|
||||
|
||||
if (rayTrace == null) {
|
||||
int currentEssence = NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).getCurrentEssence();
|
||||
List<ITextComponent> toSend = new ArrayList<ITextComponent>();
|
||||
if (!getOwnerName(stack).equals(PlayerHelper.getUsernameFromPlayer(player)))
|
||||
toSend.add(new TextComponentTranslation(tooltipBase + "otherNetwork", getOwnerName(stack)));
|
||||
Binding binding = getBinding(stack);
|
||||
if (binding != null) {
|
||||
int currentEssence = NetworkHelper.getSoulNetwork(binding).getCurrentEssence();
|
||||
List<ITextComponent> toSend = Lists.newArrayList();
|
||||
if (!binding.getOwnerId().equals(player.getGameProfile().getId()))
|
||||
toSend.add(new TextComponentTranslation(tooltipBase + "otherNetwork", binding.getOwnerName()));
|
||||
toSend.add(new TextComponentTranslation(tooltipBase + "currentEssence", currentEssence));
|
||||
ChatUtil.sendNoSpam(player, toSend.toArray(new ITextComponent[toSend.size()]));
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import WayofTime.bloodmagic.client.key.IKeybindable;
|
|||
import WayofTime.bloodmagic.client.key.KeyBindings;
|
||||
import WayofTime.bloodmagic.util.Utils;
|
||||
import WayofTime.bloodmagic.util.helper.TextHelper;
|
||||
import com.google.common.base.Strings;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -90,7 +89,7 @@ public class ItemSigilHolding extends ItemSigilBase implements IKeybindable, IAl
|
|||
List<ItemStack> inv = getInternalInventory(stack);
|
||||
ItemStack itemUsing = inv.get(currentSlot);
|
||||
|
||||
if (itemUsing.isEmpty() || Strings.isNullOrEmpty(((IBindable) itemUsing.getItem()).getOwnerUUID(itemUsing)))
|
||||
if (itemUsing.isEmpty() || ((IBindable) itemUsing.getItem()).getBinding(stack) == null)
|
||||
return EnumActionResult.PASS;
|
||||
|
||||
EnumActionResult result = itemUsing.getItem().onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
|
||||
|
@ -109,7 +108,7 @@ public class ItemSigilHolding extends ItemSigilBase implements IKeybindable, IAl
|
|||
List<ItemStack> inv = getInternalInventory(stack);
|
||||
ItemStack itemUsing = inv.get(currentSlot);
|
||||
|
||||
if (itemUsing.isEmpty() || Strings.isNullOrEmpty(((IBindable) itemUsing.getItem()).getOwnerUUID(itemUsing)))
|
||||
if (itemUsing.isEmpty() || ((IBindable) itemUsing.getItem()).getBinding(stack) == null)
|
||||
return ActionResult.newResult(EnumActionResult.PASS, stack);
|
||||
|
||||
itemUsing.getItem().onItemRightClick(world, player, hand);
|
||||
|
|
|
@ -59,7 +59,7 @@ public class ItemSigilLava extends ItemSigilBase {
|
|||
return super.onItemRightClick(world, player, hand);
|
||||
}
|
||||
|
||||
if (this.canPlaceLava(world, blockpos1) && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceLava(world, blockpos1)) {
|
||||
if (this.canPlaceLava(world, blockpos1) && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceLava(world, blockpos1)) {
|
||||
return super.onItemRightClick(world, player, hand);
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ public class ItemSigilLava extends ItemSigilBase {
|
|||
FluidStack fluid = new FluidStack(FluidRegistry.LAVA, 1000);
|
||||
int amount = handler.fill(fluid, false);
|
||||
|
||||
if (amount > 0 && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed())) {
|
||||
if (amount > 0 && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, getLpUsed())) {
|
||||
handler.fill(fluid, true);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public class ItemSigilTeleposition extends ItemSigilBase {
|
|||
if (!world.isRemote && NBTHelper.checkNBT(stack) != null && stack.getTagCompound().hasKey(Constants.NBT.DIMENSION_ID) && stack.getTagCompound().hasKey(Constants.NBT.X_COORD) && stack.getTagCompound().hasKey(Constants.NBT.Y_COORD) && stack.getTagCompound().hasKey(Constants.NBT.Z_COORD)) {
|
||||
BlockPos blockPos = new BlockPos(getValue(stack.getTagCompound(), Constants.NBT.X_COORD), getValue(stack.getTagCompound(), Constants.NBT.Y_COORD), getValue(stack.getTagCompound(), Constants.NBT.Z_COORD)).up();
|
||||
if (world.provider.getDimension() == getValue(stack.getTagCompound(), Constants.NBT.DIMENSION_ID)) {
|
||||
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(blockPos, player, getOwnerUUID(stack), true));
|
||||
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(blockPos, player, getBinding(stack).getOwnerId(), true));
|
||||
}
|
||||
// FIXME - Fix cross-dimension teleports causing major desync
|
||||
// } else {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package WayofTime.bloodmagic.item.sigil;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.core.data.Binding;
|
||||
import WayofTime.bloodmagic.item.ItemSigilToggleable;
|
||||
import WayofTime.bloodmagic.util.helper.PlayerHelper;
|
||||
import WayofTime.bloodmagic.client.IMeshProvider;
|
||||
|
@ -21,6 +22,7 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
|
||||
public class ItemSigilToggleableBase extends ItemSigilToggleable implements IMeshProvider {
|
||||
|
||||
protected final String tooltipBase;
|
||||
private final String name;
|
||||
|
||||
|
@ -40,10 +42,12 @@ public class ItemSigilToggleableBase extends ItemSigilToggleable implements IMes
|
|||
super.addInformation(stack, world, tooltip, flag);
|
||||
if (!stack.hasTagCompound())
|
||||
return;
|
||||
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic." + (getActivated(stack) ? "activated" : "deactivated")));
|
||||
|
||||
if (!Strings.isNullOrEmpty(getOwnerName(stack)))
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", PlayerHelper.getUsernameFromStack(stack)));
|
||||
Binding binding = getBinding(stack);
|
||||
if (binding != null)
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -99,7 +99,7 @@ public class ItemSigilTransposition extends ItemSigilBase {
|
|||
stack.getTagCompound().setByte(Constants.NBT.CONTAINED_BLOCK_META, metadata);
|
||||
stack.getTagCompound().setTag(Constants.NBT.CONTAINED_TILE_ENTITY, tileNBTTag);
|
||||
|
||||
NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, cost);
|
||||
NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, cost);
|
||||
|
||||
world.removeTileEntity(blockPos);
|
||||
world.setBlockToAir(blockPos);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package WayofTime.bloodmagic.item.sigil;
|
||||
|
||||
import WayofTime.bloodmagic.core.data.SoulNetwork;
|
||||
import WayofTime.bloodmagic.iface.ISigil;
|
||||
import WayofTime.bloodmagic.util.helper.NetworkHelper;
|
||||
import WayofTime.bloodmagic.util.helper.PlayerHelper;
|
||||
|
@ -85,12 +86,13 @@ public class ItemSigilVoid extends ItemSigilBase {
|
|||
return EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
SoulNetwork network = NetworkHelper.getSoulNetwork(getBinding(stack));
|
||||
TileEntity tile = world.getTileEntity(blockPos);
|
||||
if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
|
||||
IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
|
||||
FluidStack amount = handler.drain(1000, false);
|
||||
|
||||
if (amount != null && amount.amount > 0 && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed())) {
|
||||
if (amount != null && amount.amount > 0 && network.syphonAndDamage(player, getLpUsed())) {
|
||||
handler.drain(1000, true);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
@ -104,7 +106,7 @@ public class ItemSigilVoid extends ItemSigilBase {
|
|||
return EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
if (world.getBlockState(newPos).getBlock() instanceof IFluidBlock && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed())) {
|
||||
if (world.getBlockState(newPos).getBlock() instanceof IFluidBlock && network.syphonAndDamage(player, getLpUsed())) {
|
||||
world.setBlockToAir(newPos);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class ItemSigilWater extends ItemSigilBase {
|
|||
if (!player.canPlayerEdit(blockpos1, rayTrace.sideHit, stack))
|
||||
return super.onItemRightClick(world, player, hand);
|
||||
|
||||
if (this.canPlaceWater(world, blockpos1) && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceWater(world, blockpos1))
|
||||
if (this.canPlaceWater(world, blockpos1) && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceWater(world, blockpos1))
|
||||
return super.onItemRightClick(world, player, hand);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue