More work on rift remover
Reverted most changes back to SenseiKiwi's code, but fixed it not raytracing.
This commit is contained in:
parent
3e74f60807
commit
2f98bf91e8
1 changed files with 62 additions and 21 deletions
|
@ -37,13 +37,16 @@ public class itemRiftRemover extends Item
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||||
{
|
{
|
||||||
/**
|
// We invoke PlayerControllerMP.onPlayerRightClick() from here so that Minecraft
|
||||||
* Im not exactly sure why this was done with onItemFirstUse before, but that is what was causing the issue.
|
// will invoke onItemUseFirst() on the client side. We'll tell it to pass the
|
||||||
* OnItemRightClick would only be called if there was no block to be clicked on, and because we never actually click on rifts (instead we raytrace them)
|
// request to the server, which will make sure that rift-related changes are
|
||||||
* we need a method that is always called. We can update other clients of the visual information using the rift TE, by having it send a packet to all players in a radius.
|
// reflected on the server.
|
||||||
* I will need to look at the new network code first, though.
|
|
||||||
*/
|
if (!world.isRemote)
|
||||||
//Raytrace for rift block because they dont have any collision
|
{
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(world, player, true);
|
MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(world, player, true);
|
||||||
if (hit != null)
|
if (hit != null)
|
||||||
{
|
{
|
||||||
|
@ -55,20 +58,9 @@ public class itemRiftRemover extends Item
|
||||||
if (world.getBlockId(hx, hy, hz) == mod_pocketDim.blockRift.blockID && link != null &&
|
if (world.getBlockId(hx, hy, hz) == mod_pocketDim.blockRift.blockID && link != null &&
|
||||||
player.canPlayerEdit(hx, hy, hz, hit.sideHit, stack))
|
player.canPlayerEdit(hx, hy, hz, hit.sideHit, stack))
|
||||||
{
|
{
|
||||||
// Tell the rift's tile entity to do its removal animation
|
// Invoke onPlayerRightClick()
|
||||||
// Handle server client stuff on the rift TE
|
FMLClientHandler.instance().getClient().playerController.onPlayerRightClick(
|
||||||
TileEntity tileEntity = world.getBlockTileEntity(hx, hy, hz);
|
player, world, stack, hx, hy, hz, hit.sideHit, hit.hitVec);
|
||||||
if (tileEntity != null && tileEntity instanceof TileEntityRift)
|
|
||||||
{
|
|
||||||
((TileEntityRift) tileEntity).shouldClose = true;
|
|
||||||
tileEntity.onInventoryChanged();
|
|
||||||
}
|
|
||||||
if (!player.capabilities.isCreativeMode)
|
|
||||||
{
|
|
||||||
stack.damageItem(1, player);
|
|
||||||
}
|
|
||||||
player.worldObj.playSoundAtEntity(player, "mods.DimDoors.sfx.riftClose", 0.8f, 1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return stack;
|
return stack;
|
||||||
|
@ -77,6 +69,55 @@ public class itemRiftRemover extends Item
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// We want to use onItemUseFirst() here so that this code will run on the server side,
|
||||||
|
// so we don't need the client to send link-related updates to the server. Still,
|
||||||
|
// check whether we have a rift in sight before passing the request over.
|
||||||
|
|
||||||
|
// On integrated servers, the link won't be removed immediately because of the rift
|
||||||
|
// removal animation. That means we'll have a chance to check for the link before
|
||||||
|
// it's deleted. Otherwise the Rift Remover's durability wouldn't drop.
|
||||||
|
MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(world, player, true);
|
||||||
|
if (hit != null)
|
||||||
|
{
|
||||||
|
x = hit.blockX;
|
||||||
|
y = hit.blockY;
|
||||||
|
z = hit.blockZ;
|
||||||
|
|
||||||
|
NewDimData dimension = PocketManager.getDimensionData(world);
|
||||||
|
DimLink link = dimension.getLink(x, y, z);
|
||||||
|
if (world.getBlockId(x, y, z) == mod_pocketDim.blockRift.blockID && link != null &&
|
||||||
|
player.canPlayerEdit(x, y, z, side, stack))
|
||||||
|
{
|
||||||
|
// Tell the rift's tile entity to do its removal animation
|
||||||
|
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||||
|
if (tileEntity != null && tileEntity instanceof TileEntityRift)
|
||||||
|
{
|
||||||
|
((TileEntityRift) tileEntity).shouldClose = true;
|
||||||
|
tileEntity.onInventoryChanged();
|
||||||
|
}
|
||||||
|
else if (!world.isRemote)
|
||||||
|
{
|
||||||
|
// Only set the block to air on the server side so that we don't
|
||||||
|
// tell the server to remove the rift block before it can use the
|
||||||
|
// Rift Remover. Otherwise, it won't know to reduce durability.
|
||||||
|
world.setBlockToAir(x, y, z);
|
||||||
|
}
|
||||||
|
if (world.isRemote)
|
||||||
|
{
|
||||||
|
// Tell the server about this
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!player.capabilities.isCreativeMode)
|
||||||
|
{
|
||||||
|
stack.damageItem(1, player);
|
||||||
|
}
|
||||||
|
player.worldObj.playSoundAtEntity(player, "mods.DimDoors.sfx.riftClose", 0.8f, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue