Finished CraftingManager.

This commit is contained in:
zangamj 2016-08-05 10:49:05 -04:00
parent 1ee1583a06
commit 23e57a9cca
2 changed files with 35 additions and 79 deletions

View file

@ -16,8 +16,7 @@ import net.minecraftforge.fml.common.network.FMLNetworkEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
public class ConnectionHandler public class ConnectionHandler {
{
@SubscribeEvent @SubscribeEvent
public void serverConnectionFromClientEvent(FMLNetworkEvent.ServerConnectionFromClientEvent event) { public void serverConnectionFromClientEvent(FMLNetworkEvent.ServerConnectionFromClientEvent event) {
if (FMLCommonHandler.instance().getSide() == Side.SERVER) { if (FMLCommonHandler.instance().getSide() == Side.SERVER) {
@ -25,10 +24,10 @@ public class ConnectionHandler
FMLEmbeddedChannel channel = NetworkRegistry.INSTANCE.getChannel("FORGE", Side.SERVER); FMLEmbeddedChannel channel = NetworkRegistry.INSTANCE.getChannel("FORGE", Side.SERVER);
for (NewDimData data : PocketManager.getDimensions()) { for (NewDimData data : PocketManager.getDimensions()) {
try { try {
if (data.isPocketDimension() || data.id() == DDProperties.instance().LimboDimensionID) { int id = data.id();
channel.writeOutbound(new ForgeMessage.DimensionRegisterMessage(data.id(), DimensionManager.getProviderType(data.id()))); if (data.isPocketDimension() || id == DDProperties.instance().LimboDimensionID)
} channel.writeOutbound(new ForgeMessage.DimensionRegisterMessage(id,
DimensionManager.getProviderType(id)));
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@ -37,16 +36,11 @@ public class ConnectionHandler
} }
@SubscribeEvent @SubscribeEvent
public void connectionClosed(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) public void connectionClosed(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {PocketManager.tryUnload();}
{
PocketManager.tryUnload();
}
@SubscribeEvent @SubscribeEvent
public void playerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) public void playerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
{
// Hax... please don't do this! >_< // Hax... please don't do this! >_<
DimDoorsNetwork.sendToPlayer(new ClientJoinPacket(), event.player); DimDoorsNetwork.sendToPlayer(new ClientJoinPacket(), event.player);
} }
} }

View file

@ -14,16 +14,10 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapedOreRecipe;
import com.zixiken.dimdoors.items.ItemDDKey; import com.zixiken.dimdoors.items.ItemDDKey;
public class CraftingManager public class CraftingManager {
{ public static void registerRecipes(DDProperties properties) {
CraftingManager() { }
public static void registerRecipes(DDProperties properties)
{
if (properties.CraftingStableFabricAllowed) if (properties.CraftingStableFabricAllowed)
{ switch (properties.WorldThreadRequirementLevel) {
switch (properties.WorldThreadRequirementLevel)
{
case 1: case 1:
GameRegistry.addShapelessRecipe(new ItemStack(DimDoors.itemStableFabric, 1), GameRegistry.addShapelessRecipe(new ItemStack(DimDoors.itemStableFabric, 1),
Items.ender_pearl, DimDoors.itemWorldThread); Items.ender_pearl, DimDoors.itemWorldThread);
@ -39,79 +33,57 @@ public class CraftingManager
default: default:
GameRegistry.addRecipe(new ItemStack(DimDoors.itemStableFabric, 1), GameRegistry.addRecipe(new ItemStack(DimDoors.itemStableFabric, 1),
"yyy", "yxy", "yyy", 'x', Items.ender_pearl, 'y', DimDoors.itemWorldThread); "yyy", "yxy", "yyy", 'x', Items.ender_pearl, 'y', DimDoors.itemWorldThread);
break;
}
} }
if (properties.CraftingDimensionalDoorAllowed) if (properties.CraftingDimensionalDoorAllowed)
{
GameRegistry.addRecipe(new ItemStack(DimDoors.itemDimensionalDoor, 1), GameRegistry.addRecipe(new ItemStack(DimDoors.itemDimensionalDoor, 1),
"yxy", 'x', DimDoors.itemStableFabric, 'y', Items.iron_door); "yxy", 'x', DimDoors.itemStableFabric, 'y', Items.iron_door);
}
if (properties.CraftingUnstableDoorAllowed) if (properties.CraftingUnstableDoorAllowed)
{
GameRegistry.addRecipe(new ItemStack(DimDoors.itemUnstableDoor, 1), GameRegistry.addRecipe(new ItemStack(DimDoors.itemUnstableDoor, 1),
"yxy", 'x', Items.ender_eye, 'y', DimDoors.itemDimensionalDoor); "yxy", 'x', Items.ender_eye, 'y', DimDoors.itemDimensionalDoor);
}
if (properties.CraftingWarpDoorAllowed)
{
if (properties.CraftingWarpDoorAllowed)
GameRegistry.addRecipe(new ItemStack(DimDoors.itemWarpDoor, 1), GameRegistry.addRecipe(new ItemStack(DimDoors.itemWarpDoor, 1),
"yxy", 'x', Items.ender_pearl, 'y', Items.oak_door); "yxy", 'x', Items.ender_pearl, 'y', Items.oak_door);
}
if (properties.CraftingTransTrapdoorAllowed)
{
if (properties.CraftingTransTrapdoorAllowed)
GameRegistry.addRecipe(new ItemStack(DimDoors.transTrapdoor, 1), GameRegistry.addRecipe(new ItemStack(DimDoors.transTrapdoor, 1),
"y", "x", "y", 'x', Items.ender_pearl, 'y', Blocks.trapdoor); "y", "x", "y", 'x', Items.ender_pearl, 'y', Blocks.trapdoor);
}
if (properties.CraftingRiftSignatureAllowed)
{
if (properties.CraftingRiftSignatureAllowed)
GameRegistry.addRecipe(new ItemStack(DimDoors.itemRiftSignature, 1), GameRegistry.addRecipe(new ItemStack(DimDoors.itemRiftSignature, 1),
" y ", "yxy", " y ", 'x', Items.ender_pearl, 'y', Items.iron_ingot); " y ", "yxy", " y ", 'x', Items.ender_pearl, 'y', Items.iron_ingot);
}
if (properties.CraftingRiftRemoverAllowed)
{
if (properties.CraftingRiftRemoverAllowed)
GameRegistry.addRecipe(new ItemStack(DimDoors.itemRiftRemover, 1), GameRegistry.addRecipe(new ItemStack(DimDoors.itemRiftRemover, 1),
"yyy", "yxy", "yyy", 'x', Items.ender_pearl, 'y', Items.gold_ingot); "yyy", "yxy", "yyy", 'x', Items.ender_pearl, 'y', Items.gold_ingot);
}
if (properties.CraftingRiftBladeAllowed) if (properties.CraftingRiftBladeAllowed)
{
GameRegistry.addRecipe(new ItemStack(DimDoors.itemRiftBlade, 1), GameRegistry.addRecipe(new ItemStack(DimDoors.itemRiftBlade, 1),
"x", "x", "y", 'x', DimDoors.itemStableFabric, 'y', Items.blaze_rod); "x", "x", "y", 'x', DimDoors.itemStableFabric, 'y', Items.blaze_rod);
}
if (properties.CraftingStabilizedRiftSignatureAllowed)
{
if (properties.CraftingStabilizedRiftSignatureAllowed)
GameRegistry.addRecipe(new ItemStack(DimDoors.itemStabilizedRiftSignature, 1), GameRegistry.addRecipe(new ItemStack(DimDoors.itemStabilizedRiftSignature, 1),
" y ", "yxy", " y ", 'x', DimDoors.itemStableFabric, 'y', Items.iron_ingot); " y ", "yxy", " y ", 'x', DimDoors.itemStableFabric, 'y', Items.iron_ingot);
}
if (properties.CraftingGoldenDimensionalDoorAllowed) if (properties.CraftingGoldenDimensionalDoorAllowed)
{
GameRegistry.addRecipe(new ItemStack(DimDoors.itemGoldenDimensionalDoor, 1), GameRegistry.addRecipe(new ItemStack(DimDoors.itemGoldenDimensionalDoor, 1),
"yxy", 'x', DimDoors.itemStableFabric, 'y', DimDoors.itemGoldenDoor); "yxy", 'x', DimDoors.itemStableFabric, 'y', DimDoors.itemGoldenDoor);
}
if (properties.CraftingGoldenDoorAllowed) if (properties.CraftingGoldenDoorAllowed)
{
GameRegistry.addRecipe(new ItemStack(DimDoors.itemGoldenDoor, 1), GameRegistry.addRecipe(new ItemStack(DimDoors.itemGoldenDoor, 1),
"yy", "yy", "yy", 'y', Items.gold_ingot); "yy", "yy", "yy", 'y', Items.gold_ingot);
}
if (properties.CraftingPersonalDimDoorAllowed) if (properties.CraftingPersonalDimDoorAllowed)
{
GameRegistry.addRecipe(new ItemStack(DimDoors.itemPersonalDoor,1), GameRegistry.addRecipe(new ItemStack(DimDoors.itemPersonalDoor,1),
"yxy", 'y', DimDoors.itemQuartzDoor, 'x', DimDoors.itemStableFabric); "yxy", 'y', DimDoors.itemQuartzDoor, 'x', DimDoors.itemStableFabric);
}
if (properties.CraftingQuartzDoorAllowed) if (properties.CraftingQuartzDoorAllowed)
{ GameRegistry.addRecipe(new ShapedOreRecipe(DimDoors.itemQuartzDoor,
GameRegistry.addRecipe(new ShapedOreRecipe(DimDoors.itemQuartzDoor, new Object[]{ "yy", "yy", "yy", 'y', "oreQuartz"));
"yy", "yy", "yy", Character.valueOf('y'), "oreQuartz"}));
if (properties.CraftingDDKeysAllowed) {
}
if (properties.CraftingDDKeysAllowed)
{
GameRegistry.addRecipe(new ItemStack(DimDoors.itemDDKey, 1), GameRegistry.addRecipe(new ItemStack(DimDoors.itemDDKey, 1),
" z", " y ", "y ", 'y', Items.gold_ingot, 'z', Items.ender_pearl); " z", " y ", "y ", 'y', Items.gold_ingot, 'z', Items.ender_pearl);
GameRegistry.addRecipe(new ItemStack(DimDoors.itemDDKey, 1), GameRegistry.addRecipe(new ItemStack(DimDoors.itemDDKey, 1),
@ -121,42 +93,32 @@ public class CraftingManager
} }
@SubscribeEvent @SubscribeEvent
public void onCrafting(PlayerEvent.ItemCraftedEvent event) public void onCrafting(PlayerEvent.ItemCraftedEvent event) {
{ if(event.crafting.getItem() instanceof ItemDDKey) {
if(event.crafting.getItem() instanceof ItemDDKey)
{
ItemDDKey keyItem = (ItemDDKey) event.crafting.getItem(); ItemDDKey keyItem = (ItemDDKey) event.crafting.getItem();
ItemStack topKey = null; ItemStack topKey = null;
ItemStack bottomKey = null; ItemStack bottomKey = null;
int topKeySlot = 0;
for(int i = 0; i<event.craftMatrix.getSizeInventory();i++) for(int i = 0; i < event.craftMatrix.getSizeInventory(); i++) {
{
ItemStack slot = event.craftMatrix.getStackInSlot(i); ItemStack slot = event.craftMatrix.getStackInSlot(i);
if(slot!=null) if(slot != null) {
{ if(topKey == null) topKey = slot;
if(topKey==null) else {
{
topKey = slot;
topKeySlot = i;
}
else
{
bottomKey = slot; bottomKey = slot;
break; break;
} }
} }
} }
DDLock.addKeys(bottomKey, DDLock.getKeys(topKey)); DDLock.addKeys(bottomKey, DDLock.getKeys(topKey));
event.crafting.setTagCompound(bottomKey.getTagCompound()); event.crafting.setTagCompound(bottomKey.getTagCompound());
event.player.inventory.addItemStackToInventory(topKey); event.player.inventory.addItemStackToInventory(topKey);
} }
} }
public static void registerDispenserBehaviors() public static void registerDispenserBehaviors() {
{
// Register the dispenser behaviors for certain DD items // Register the dispenser behaviors for certain DD items
BlockDispenser.dispenseBehaviorRegistry.putObject(DimDoors.itemStabilizedRiftSignature, new DispenserBehaviorStabilizedRS()); BlockDispenser.dispenseBehaviorRegistry.putObject(
DimDoors.itemStabilizedRiftSignature, new DispenserBehaviorStabilizedRS());
} }
} }