Added Dispenser Support for SRS

Added support for using Stabilized Rift Signatures from dispensers under
specific conditions. Everything works except for playing the sound that
occurs when an SRS is used. Not sure why that's not working.
This commit is contained in:
SenseiKiwi
2014-06-26 12:11:51 -04:00
parent 444b862b12
commit 59f335ac8c
4 changed files with 101 additions and 3 deletions

View File

@@ -1,9 +1,11 @@
package StevenDimDoors.mod_pocketDim; package StevenDimDoors.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.config.DDProperties;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockDispenser;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import StevenDimDoors.mod_pocketDim.config.DDProperties;
import StevenDimDoors.mod_pocketDim.items.behaviors.DispenserBehaviorStabilizedRS;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
public class CraftingManager public class CraftingManager
@@ -87,4 +89,9 @@ public class CraftingManager
} }
} }
public static void registerDispenserBehaviors()
{
// Register the dispenser behaviors for certain DD items
BlockDispenser.dispenseBehaviorRegistry.putObject(mod_pocketDim.itemStabilizedRiftSignature, new DispenserBehaviorStabilizedRS());
}
} }

View File

@@ -45,10 +45,10 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature
{ {
return true; return true;
} }
Point4DOrientation source = getSource(stack); int orientation = MathHelper.floor_double((player.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3;
// Check if the Stabilized Rift Signature has been initialized // Check if the Stabilized Rift Signature has been initialized
int orientation = MathHelper.floor_double((player.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3; Point4DOrientation source = getSource(stack);
if (source != null) if (source != null)
{ {
// Yes, it's initialized. // Yes, it's initialized.
@@ -117,6 +117,54 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature
return true; return true;
} }
public static boolean useFromDispenser(ItemStack stack, World world, int x, int y, int z)
{
// Stabilized Rift Signatures can only be used from dispensers to restore
// a previous link pair. The operation would be free for a player, so
// dispensers can also perform it for free. Otherwise, the item does nothing.
if (world.isRemote)
{
return false;
}
// Adjust Y so the rift is at head level, depending on the presence of certain blocks
int adjustedY = adjustYForSpecialBlocks(world, x, y + 2, z);
Point4DOrientation source = getSource(stack);
// The SRS must have been initialized
if (source != null)
{
NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension());
NewDimData destinationDimension = PocketManager.getDimensionData(world);
DimLink reverse = destinationDimension.getLink(x, adjustedY, z);
DimLink link;
// Check whether the SRS is being used to restore one of its previous
// link pairs. In other words, the SRS is being used on a location
// that already has a link pointing to the SRS's source, with the
// intention of overwriting the source-side link to point there.
if (reverse != null && source.getPoint().equals(reverse.destination()))
{
// Only the source-to-destination link is needed.
link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL, source.getOrientation());
destinationDimension.setLinkDestination(link, x, adjustedY, z);
// 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);
}
// This call doesn't seem to be working...
world.playSoundEffect(x + 0.5, adjustedY + 0.5, z + 0.5, "mods.DimDoors.sfx.riftEnd", 0.6f, 1);
return true;
}
}
return false;
}
/** /**
* allows items to add custom lines of information to the mouseover description * allows items to add custom lines of information to the mouseover description
*/ */

View File

@@ -0,0 +1,42 @@
package StevenDimDoors.mod_pocketDim.items.behaviors;
import net.minecraft.block.BlockDispenser;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.items.ItemStabilizedRiftSignature;
public class DispenserBehaviorStabilizedRS extends BehaviorDefaultDispenseItem
{
@Override
public ItemStack dispenseStack(IBlockSource dispenser, ItemStack stack)
{
// Search for a non-air block up to 3 blocks in front of a dispenser.
// If it's found, call ItemStabilizedRiftSignature.useFromDispenser().
int x = dispenser.getXInt();
int y = dispenser.getYInt();
int z = dispenser.getZInt();
EnumFacing facing = BlockDispenser.getFacing(dispenser.getBlockMetadata());
int dx = facing.getFrontOffsetX();
int dy = facing.getFrontOffsetY();
int dz = facing.getFrontOffsetZ();
World world = dispenser.getWorld();
for (int k = 1; k <= 3; k++)
{
x += dx;
y += dy;
z += dz;
if (!world.isAirBlock(x, y, z))
{
// Found a block. Activate the item.
ItemStabilizedRiftSignature.useFromDispenser(stack, world, x, y, z);
break;
}
}
// The item stack isn't modified
return stack;
}
}

View File

@@ -292,6 +292,7 @@ public class mod_pocketDim
LanguageRegistry.instance().addStringLocalization("entity.DimDoors.Obelisk.name", "Monolith"); LanguageRegistry.instance().addStringLocalization("entity.DimDoors.Obelisk.name", "Monolith");
CraftingManager.registerRecipes(properties); CraftingManager.registerRecipes(properties);
CraftingManager.registerDispenserBehaviors();
DungeonHelper.initialize(); DungeonHelper.initialize();
gatewayGenerator = new GatewayGenerator(properties); gatewayGenerator = new GatewayGenerator(properties);
GameRegistry.registerWorldGenerator(mod_pocketDim.gatewayGenerator); GameRegistry.registerWorldGenerator(mod_pocketDim.gatewayGenerator);