Fixed Various Bugs #83
@@ -24,9 +24,9 @@ public class ItemRiftSignature extends Item
|
|||||||
{
|
{
|
||||||
super(itemID);
|
super(itemID);
|
||||||
this.setMaxStackSize(1);
|
this.setMaxStackSize(1);
|
||||||
this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab);
|
|
||||||
this.setMaxDamage(0);
|
this.setMaxDamage(0);
|
||||||
this.hasSubtypes = true;
|
this.hasSubtypes = true;
|
||||||
|
this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
@@ -43,67 +43,69 @@ public class ItemRiftSignature extends Item
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10)
|
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||||
{
|
{
|
||||||
tryItemUse(stack, player, world, x, y, z);
|
// We must use onItemUseFirst() instead of onItemUse() because Minecraft checks
|
||||||
return true;
|
// whether the user is in creative mode after calling onItemUse() and undoes any
|
||||||
}
|
// damage we might set to indicate the rift sig has been activated. Otherwise,
|
||||||
|
// we would need to rely on checking NBT tags for hasEffect() and that function
|
||||||
protected boolean tryItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z)
|
// gets called constantly. Avoiding NBT lookups reduces our performance impact.
|
||||||
{
|
|
||||||
if (!world.isRemote)
|
// Return false on the client side to pass this request to the server
|
||||||
|
if (world.isRemote)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//We don't check for replaceable blocks. The user can deal with that. <_<
|
||||||
|
|
||||||
|
y += 2; //Increase y by 2 to place the rift at head level
|
||||||
|
if (!player.canPlayerEdit(x, y, z, 0, stack))
|
||||||
{
|
{
|
||||||
//We don't check for replaceable blocks. The user can deal with that. <_<
|
|
||||||
|
|
||||||
y += 2; //Increase y by 2 to place the rift at head level
|
|
||||||
if (!player.canPlayerEdit(x, y, z, 0, stack))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point4D source = getSource(stack);
|
|
||||||
if (source != null)
|
|
||||||
{
|
|
||||||
//The link was used before and already has an endpoint stored. Create links connecting the two endpoints.
|
|
||||||
NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension());
|
|
||||||
NewDimData destinationDimension = PocketManager.getDimensionData(world);
|
|
||||||
DimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL);
|
|
||||||
DimLink reverse = destinationDimension.createLink(x, y, z, LinkTypes.NORMAL);
|
|
||||||
destinationDimension.setDestination(link, x, y, z);
|
|
||||||
sourceDimension.setDestination(reverse, source.getX(), source.getY(), source.getZ());
|
|
||||||
|
|
||||||
//Try placing a rift at the destination point
|
|
||||||
if (!mod_pocketDim.blockRift.isBlockImmune(world, x, y, z))
|
|
||||||
{
|
|
||||||
world.setBlock(x, y, z, mod_pocketDim.blockRift.blockID);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Try placing a rift at the source point, but check if its world is loaded first
|
|
||||||
World sourceWorld = DimensionManager.getWorld(sourceDimension.id());
|
|
||||||
if (sourceWorld != null &&
|
|
||||||
!mod_pocketDim.blockRift.isBlockImmune(sourceWorld, source.getX(), source.getY(), source.getZ()))
|
|
||||||
{
|
|
||||||
sourceWorld.setBlock(source.getX(), source.getY(), source.getY(), mod_pocketDim.blockRift.blockID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!player.capabilities.isCreativeMode)
|
|
||||||
{
|
|
||||||
stack.stackSize--;
|
|
||||||
}
|
|
||||||
clearSource(stack);
|
|
||||||
player.sendChatToPlayer("Rift Created");
|
|
||||||
world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftEnd", 0.6f, 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//The link signature has not been used. Store its current target as the first location.
|
|
||||||
setSource(stack, x, y, z, PocketManager.getDimensionData(world));
|
|
||||||
player.sendChatToPlayer("Location Stored in Rift Signature");
|
|
||||||
world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftStart", 0.6f, 1);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
Point4D source = getSource(stack);
|
||||||
|
if (source != null)
|
||||||
|
{
|
||||||
|
//The link was used before and already has an endpoint stored. Create links connecting the two endpoints.
|
||||||
|
NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension());
|
||||||
|
NewDimData destinationDimension = PocketManager.getDimensionData(world);
|
||||||
|
DimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL);
|
||||||
|
DimLink reverse = destinationDimension.createLink(x, y, z, LinkTypes.NORMAL);
|
||||||
|
destinationDimension.setDestination(link, x, y, z);
|
||||||
|
sourceDimension.setDestination(reverse, source.getX(), source.getY(), source.getZ());
|
||||||
|
|
||||||
|
//Try placing a rift at the destination point
|
||||||
|
if (!mod_pocketDim.blockRift.isBlockImmune(world, x, y, z))
|
||||||
|
{
|
||||||
|
world.setBlock(x, y, z, mod_pocketDim.blockRift.blockID);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Try placing a rift at the source point, but check if its world is loaded first
|
||||||
|
World sourceWorld = DimensionManager.getWorld(sourceDimension.id());
|
||||||
|
if (sourceWorld != null &&
|
||||||
|
!mod_pocketDim.blockRift.isBlockImmune(sourceWorld, source.getX(), source.getY(), source.getZ()))
|
||||||
|
{
|
||||||
|
sourceWorld.setBlock(source.getX(), source.getY(), source.getZ(), mod_pocketDim.blockRift.blockID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!player.capabilities.isCreativeMode)
|
||||||
|
{
|
||||||
|
stack.stackSize--;
|
||||||
|
}
|
||||||
|
clearSource(stack);
|
||||||
|
player.sendChatToPlayer("Rift Created");
|
||||||
|
world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftEnd", 0.6f, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//The link signature has not been used. Store its current target as the first location.
|
||||||
|
setSource(stack, x, y, z, PocketManager.getDimensionData(world));
|
||||||
|
player.sendChatToPlayer("Location Stored in Rift Signature");
|
||||||
|
world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftStart", 0.6f, 1);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,7 +140,7 @@ public class ItemRiftSignature extends Item
|
|||||||
itemStack.setTagCompound(tag);
|
itemStack.setTagCompound(tag);
|
||||||
itemStack.setItemDamage(1);
|
itemStack.setItemDamage(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearSource(ItemStack itemStack)
|
public static void clearSource(ItemStack itemStack)
|
||||||
{
|
{
|
||||||
//Don't just set the tag to null since there may be other data there (e.g. for renamed items)
|
//Don't just set the tag to null since there may be other data there (e.g. for renamed items)
|
||||||
@@ -149,7 +151,7 @@ public class ItemRiftSignature extends Item
|
|||||||
tag.removeTag("linkDimID");
|
tag.removeTag("linkDimID");
|
||||||
itemStack.setItemDamage(0);
|
itemStack.setItemDamage(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Point4D getSource(ItemStack itemStack)
|
public static Point4D getSource(ItemStack itemStack)
|
||||||
{
|
{
|
||||||
if (itemStack.getItemDamage() != 0)
|
if (itemStack.getItemDamage() != 0)
|
||||||
@@ -157,12 +159,12 @@ public class ItemRiftSignature extends Item
|
|||||||
if (itemStack.hasTagCompound())
|
if (itemStack.hasTagCompound())
|
||||||
{
|
{
|
||||||
NBTTagCompound tag = itemStack.getTagCompound();
|
NBTTagCompound tag = itemStack.getTagCompound();
|
||||||
|
|
||||||
Integer x = tag.getInteger("linkX");
|
Integer x = tag.getInteger("linkX");
|
||||||
Integer y = tag.getInteger("linkY");
|
Integer y = tag.getInteger("linkY");
|
||||||
Integer z = tag.getInteger("linkZ");
|
Integer z = tag.getInteger("linkZ");
|
||||||
Integer dimID = tag.getInteger("linkDimID");
|
Integer dimID = tag.getInteger("linkDimID");
|
||||||
|
|
||||||
if (x != null && y != null && z != null && dimID != null)
|
if (x != null && y != null && z != null && dimID != null)
|
||||||
{
|
{
|
||||||
return new Point4D(x, y, z, dimID);
|
return new Point4D(x, y, z, dimID);
|
||||||
|
|||||||
@@ -7,65 +7,113 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.DimensionManager;
|
||||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||||
|
import StevenDimDoors.mod_pocketDim.core.DimLink;
|
||||||
|
import StevenDimDoors.mod_pocketDim.core.LinkTypes;
|
||||||
|
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
||||||
|
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||||
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
public class ItemStabilizedRiftSignature extends ItemRiftSignature
|
public class ItemStabilizedRiftSignature extends ItemRiftSignature
|
||||||
{
|
{
|
||||||
public ItemStabilizedRiftSignature(int itemID)
|
public ItemStabilizedRiftSignature(int itemID)
|
||||||
{
|
{
|
||||||
super(itemID);
|
super(itemID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerIcons(IconRegister par1IconRegister)
|
|
||||||
{
|
|
||||||
this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", ""));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public void registerIcons(IconRegister par1IconRegister)
|
||||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10)
|
{
|
||||||
{
|
this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", ""));
|
||||||
//Check if the Stabilized Rift Signature has been initialized
|
}
|
||||||
Point4D source = getSource(stack);
|
|
||||||
if (source != null)
|
@Override
|
||||||
{
|
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||||
//Yes, it's initialized. Check if the player can pay an Ender Pearl to create a rift.
|
{
|
||||||
if (player.inventory.hasItem(Item.enderPearl.itemID))
|
// Return false on the client side to pass this request to the server
|
||||||
{
|
if (world.isRemote)
|
||||||
if (tryItemUse(stack, player, world, x, y, z) && !player.capabilities.isCreativeMode)
|
{
|
||||||
{
|
return false;
|
||||||
player.inventory.consumeInventoryItem(Item.enderPearl.itemID);
|
}
|
||||||
}
|
|
||||||
}
|
// We don't check for replaceable blocks. The user can deal with that. <_<
|
||||||
}
|
y += 2; //Increase y by 2 to place the rift at head level
|
||||||
else
|
if (!player.canPlayerEdit(x, y, z, 0, stack))
|
||||||
{
|
{
|
||||||
//Initialization doesn't cost any materials
|
return true;
|
||||||
tryItemUse(stack, player, world, x, y, z);
|
}
|
||||||
}
|
|
||||||
return true;
|
// Check if the Stabilized Rift Signature has been initialized
|
||||||
}
|
Point4D source = getSource(stack);
|
||||||
|
if (source != null)
|
||||||
/**
|
{
|
||||||
* allows items to add custom lines of information to the mouseover description
|
// Yes, it's initialized. Check if the player is in creative
|
||||||
*/
|
// or if the player can pay an Ender Pearl to create a rift.
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
if (!player.capabilities.isCreativeMode && !player.inventory.hasItem(Item.enderPearl.itemID))
|
||||||
|
{
|
||||||
|
player.sendChatToPlayer("You don't have any Ender Pearls!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//The link was used before and already has an endpoint stored. Create links connecting the two endpoints.
|
||||||
|
NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension());
|
||||||
|
NewDimData destinationDimension = PocketManager.getDimensionData(world);
|
||||||
|
DimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL);
|
||||||
|
DimLink reverse = destinationDimension.createLink(x, y, z, LinkTypes.NORMAL);
|
||||||
|
destinationDimension.setDestination(link, x, y, z);
|
||||||
|
sourceDimension.setDestination(reverse, source.getX(), source.getY(), source.getZ());
|
||||||
|
|
||||||
|
//Try placing a rift at the destination point
|
||||||
|
if (!mod_pocketDim.blockRift.isBlockImmune(world, x, y, z))
|
||||||
|
{
|
||||||
|
world.setBlock(x, y, z, mod_pocketDim.blockRift.blockID);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Try placing a rift at the source point, but check if its world is loaded first
|
||||||
|
World sourceWorld = DimensionManager.getWorld(sourceDimension.id());
|
||||||
|
if (sourceWorld != null &&
|
||||||
|
!mod_pocketDim.blockRift.isBlockImmune(sourceWorld, source.getX(), source.getY(), source.getZ()))
|
||||||
|
{
|
||||||
|
sourceWorld.setBlock(source.getX(), source.getY(), source.getZ(), mod_pocketDim.blockRift.blockID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!player.capabilities.isCreativeMode)
|
||||||
|
{
|
||||||
|
player.inventory.consumeInventoryItem(Item.enderPearl.itemID);
|
||||||
|
}
|
||||||
|
player.sendChatToPlayer("Rift Created");
|
||||||
|
world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftEnd", 0.6f, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//The link signature has not been used. Store its current target as the first location.
|
||||||
|
setSource(stack, x, y, z, PocketManager.getDimensionData(world));
|
||||||
|
player.sendChatToPlayer("Location Stored in Rift Signature");
|
||||||
|
world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftStart", 0.6f, 1);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* allows items to add custom lines of information to the mouseover description
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
@Override
|
@Override
|
||||||
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
|
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
|
||||||
{
|
{
|
||||||
Point4D source = getSource(par1ItemStack);
|
Point4D source = getSource(par1ItemStack);
|
||||||
if (source != null)
|
if (source != null)
|
||||||
{
|
{
|
||||||
par3List.add("Leads to (" + source.getX() + ", " + source.getY() + ", " + source.getZ() + ") at dimension #" + source.getDimension());
|
par3List.add("Leads to (" + source.getX() + ", " + source.getY() + ", " + source.getZ() + ") at dimension #" + source.getDimension());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
par3List.add("First click stores a location,");
|
par3List.add("First click stores a location,");
|
||||||
par3List.add("second click creates two rifts");
|
par3List.add("second click creates two rifts");
|
||||||
par3List.add("that link the locations together.");
|
par3List.add("that link the locations together.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user