This commit is contained in:
Tschipp 2018-08-14 23:37:50 +02:00
parent bca7534257
commit cda44221f7
13 changed files with 456 additions and 92 deletions

View File

@ -41,7 +41,7 @@ repositories {
dependencies {
deobfCompile "net.darkhax.gamestages:GameStages-1.12.2:2.0.91"
// deobfCompile "net.darkhax.gamestages:GameStages-1.12.2:2.0.91"
}

View File

@ -32,12 +32,12 @@ public class CarryOn {
public static CarryOn instance;
public static final String MODID = "carryon";
public static final String VERSION = "1.9.2";
public static final String VERSION = "1.10";
public static final String NAME = "Carry On";
public static final String ACCEPTED_VERSIONS = "[1.12.2,1.13)";
public static final String UPDATE_JSON = "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/";
public static final Logger LOGGER = LogManager.getFormatterLogger("CarryOn");
public static final String DEPENDENCIES = "required-after:forge@[13.20.1.2386,);after:gamestages@[2.0.91,)";
public static final String DEPENDENCIES = "required-after:forge@[13.20.1.2386,);after:gamestages;";
public static File CONFIGURATION_FILE;
public static SimpleNetworkWrapper network;

View File

@ -35,6 +35,7 @@ import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@ -104,6 +105,21 @@ public class RenderEvents
}
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onJoinWorld(EntityJoinWorldEvent event)
{
if (event.getEntity() instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) event.getEntity();
if (player.world.isRemote)
{
CarryOnKeybinds.setKeyPressed(player, false);
CarryOn.network.sendToServer(new SyncKeybindPacket(false));
}
}
}
/*
* Prevents the Player from opening Guis
*/
@ -199,6 +215,7 @@ public class RenderEvents
GlStateManager.pushMatrix();
GlStateManager.scale(2.5, 2.5, 2.5);
GlStateManager.translate(0, -0.6, -1);
GlStateManager.enableBlend();
if (CarryOnConfig.settings.facePlayer ? !isChest(block) : isChest(block))
{
@ -269,6 +286,7 @@ public class RenderEvents
event.setCanceled(true);
}
GlStateManager.disableBlend();
GlStateManager.scale(1, 1, 1);
GlStateManager.popMatrix();
@ -350,6 +368,7 @@ public class RenderEvents
GlStateManager.pushMatrix();
GlStateManager.translate(xOffset, yOffset, zOffset);
GlStateManager.scale(0.6, 0.6, 0.6);
GlStateManager.enableBlend();
if (CarryOnConfig.settings.facePlayer ? !isChest(block) : isChest(block))
{
@ -415,6 +434,7 @@ public class RenderEvents
Minecraft.getMinecraft().getRenderItem().renderItem(tileItem.isEmpty() ? stack : tileItem, model);
}
GlStateManager.disableBlend();
GlStateManager.scale(1, 1, 1);
GlStateManager.popMatrix();
}
@ -424,7 +444,7 @@ public class RenderEvents
* Renders correct arm rotation
*/
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.NORMAL)
@SubscribeEvent(priority = EventPriority.HIGH)
public void onEvent(RenderPlayerEvent.Post event)
{
if (handleMobends())
@ -594,7 +614,7 @@ public class RenderEvents
if (Loader.isModLoaded("mobends"))
{
Configuration config = new Configuration(new File(CarryOn.CONFIGURATION_FILE.getPath().substring(0, CarryOn.CONFIGURATION_FILE.getPath().length() - 16), "mobends.cfg"));
boolean renderPlayer = config.get("animated", "player", true).getBoolean();
return !renderPlayer;
}

View File

@ -150,6 +150,9 @@ public class Configs {
"thaumcraft:infusion_matrix",
"thaumcraft:golem_builder",
"thaumcraft:thaumatorium*",
"refinedstorage:*",
"practicallogistics2:*",
"mcmultipart:*",
};

View File

@ -52,6 +52,18 @@ public class ItemEntityEvents
{
player.getEntityData().removeTag("carrySlot");
event.setUseBlock(Result.DENY);
if (!player.world.isRemote)
{
CarryOnOverride override = ScriptChecker.getOverride(player);
if (override != null)
{
String command = override.getCommandPlace();
if (command != null)
player.getServer().getCommandManager().executeCommand(player.getServer(), "/execute " + player.getGameProfile().getName() + " ~ ~ ~ " + command);
}
}
}
}
@ -119,7 +131,7 @@ public class ItemEntityEvents
if (override != null)
overrideHash = override.hashCode();
CarryOn.network.sendToAllAround(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId(), overrideHash), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256));
ItemEvents.sendPacket(player, player.inventory.currentItem, overrideHash);
entity.setDead();
player.setHeldItem(EnumHand.MAIN_HAND, stack);
event.setCanceled(true);
@ -154,7 +166,7 @@ public class ItemEntityEvents
EntityHorse horse = (EntityHorse) topEntity;
horse.setHorseTamed(true);
}
if (distance < 6)
{
double tempX = entity.posX;
@ -171,11 +183,10 @@ public class ItemEntityEvents
world.spawnEntity(entityHeld);
entityHeld.startRiding(topEntity, false);
}
ItemEntity.clearEntityData(main);
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
CarryOn.network.sendToAllAround(new CarrySlotPacket(9, player.getEntityId()), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256));
ItemEvents.sendPacket(player, 9, 0);
event.setCanceled(true);
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_HORSE_SADDLE, SoundCategory.PLAYERS, 0.5F, 1.5F);
}

View File

@ -47,6 +47,7 @@ import tschipp.carryon.common.item.ItemTile;
import tschipp.carryon.common.scripting.CarryOnOverride;
import tschipp.carryon.common.scripting.ScriptChecker;
import tschipp.carryon.network.client.CarrySlotPacket;
import tschipp.carryon.network.server.SyncKeybindPacket;
public class ItemEvents
{
@ -63,6 +64,18 @@ public class ItemEvents
{
player.getEntityData().removeTag("carrySlot");
event.setUseBlock(Result.DENY);
if (!player.world.isRemote)
{
CarryOnOverride override = ScriptChecker.getOverride(player);
if (override != null)
{
String command = override.getCommandPlace();
if (command != null)
player.getServer().getCommandManager().executeCommand(player.getServer(), "/execute " + player.getGameProfile().getName() + " ~ ~ ~ " + command);
}
}
}
}
@ -224,7 +237,7 @@ public class ItemEvents
{
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
EntityItem item = new EntityItem(player.world, player.posX, player.posY, player.posZ, stack);
CarryOn.network.sendToAllAround(new CarrySlotPacket(9, player.getEntityId()), new TargetPoint(player.world.provider.getDimension(), player.posX, player.posY, player.posZ, 256));
sendPacket(player, 9, 0);
player.world.spawnEntity(item);
}
}
@ -267,29 +280,33 @@ public class ItemEvents
if (override != null)
overrideHash = override.hashCode();
boolean success = false;
try
{
CarryOn.network.sendToAllAround(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId(), overrideHash), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256));
sendPacket(player, player.inventory.currentItem, overrideHash);
world.removeTileEntity(pos);
world.setBlockToAir(pos);
player.setHeldItem(EnumHand.MAIN_HAND, stack);
event.setUseBlock(Result.DENY);
event.setCanceled(true);
success = true;
}
catch (Exception e)
{
try
{
CarryOn.network.sendToAllAround(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId(), overrideHash), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256));
sendPacket(player, player.inventory.currentItem, overrideHash);
emptyTileEntity(te);
world.setBlockToAir(pos);
player.setHeldItem(EnumHand.MAIN_HAND, stack);
event.setUseBlock(Result.DENY);
event.setCanceled(true);
success = true;
}
catch (Exception ex)
{
CarryOn.network.sendToAllAround(new CarrySlotPacket(9, player.getEntityId()), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256));
sendPacket(player, 9, 0);
world.setBlockState(pos, statee);
if (!tag.hasNoTags())
TileEntity.create(world, tag);
@ -302,6 +319,13 @@ public class ItemEvents
}
if (success && override != null)
{
String command = override.getCommandInit();
if (command != null)
player.getServer().getCommandManager().executeCommand(player.getServer(), "/execute " + player.getGameProfile().getName() + " ~ ~ ~ " + command);
}
}
}
}
@ -375,56 +399,92 @@ public class ItemEvents
item.setPosition(pos.getX(), pos.getY(), pos.getZ());
world.spawnEntity(item);
}
}
@SubscribeEvent
public void dropNonHotbarItems(LivingUpdateEvent event)
{
EntityLivingBase entity = event.getEntityLiving();
if (entity instanceof EntityPlayer && !entity.world.isRemote)
if (entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) entity;
boolean hasCarried = player.inventory.hasItemStack(new ItemStack(RegistrationHandler.itemTile)) || player.inventory.hasItemStack(new ItemStack(RegistrationHandler.itemEntity));
ItemStack inHand = player.getHeldItemMainhand();
if (hasCarried)
if (!entity.world.isRemote)
{
if (inHand.getItem() != RegistrationHandler.itemTile && inHand.getItem() != RegistrationHandler.itemEntity)
{
int slotBlock = getSlot(player, RegistrationHandler.itemTile);
int slotEntity = getSlot(player, RegistrationHandler.itemEntity);
boolean hasCarried = player.inventory.hasItemStack(new ItemStack(RegistrationHandler.itemTile)) || player.inventory.hasItemStack(new ItemStack(RegistrationHandler.itemEntity));
ItemStack inHand = player.getHeldItemMainhand();
EntityItem item = null;
if(slotBlock != -1)
if (hasCarried)
{
if (inHand.getItem() != RegistrationHandler.itemTile && inHand.getItem() != RegistrationHandler.itemEntity)
{
ItemStack dropped = player.inventory.removeStackFromSlot(slotBlock);
item = new EntityItem(player.world, player.posX, player.posY, player.posZ, dropped);
}
if(slotEntity != -1)
{
ItemStack dropped = player.inventory.removeStackFromSlot(slotEntity);
item = new EntityItem(player.world, player.posX, player.posY, player.posZ, dropped);
}
if(item != null)
{
player.world.spawnEntity(item);
CarryOn.network.sendToAllAround(new CarrySlotPacket(9, player.getEntityId()), new TargetPoint(player.world.provider.getDimension(), player.posX, player.posY, player.posZ, 256));
int slotBlock = getSlot(player, RegistrationHandler.itemTile);
int slotEntity = getSlot(player, RegistrationHandler.itemEntity);
EntityItem item = null;
if (slotBlock != -1)
{
ItemStack dropped = player.inventory.removeStackFromSlot(slotBlock);
item = new EntityItem(player.world, player.posX, player.posY, player.posZ, dropped);
}
if (slotEntity != -1)
{
ItemStack dropped = player.inventory.removeStackFromSlot(slotEntity);
item = new EntityItem(player.world, player.posX, player.posY, player.posZ, dropped);
}
if (item != null)
{
player.world.spawnEntity(item);
sendPacket(player, 9, 0);
}
}
}
CarryOnOverride override = ScriptChecker.getOverride(player);
if (override != null)
{
String command = override.getCommandLoop();
if (command != null)
player.getServer().getCommandManager().executeCommand(player.getServer(), "/execute " + player.getGameProfile().getName() + " ~ ~ ~ " + command);
}
}
}
}
public int getSlot(EntityPlayer player, Item item)
{
for(int i = 0; i < player.inventory.getSizeInventory(); i++)
for (int i = 0; i < player.inventory.getSizeInventory(); i++)
{
ItemStack stack = player.inventory.getStackInSlot(i);
if(stack.getItem() == item)
if (stack.getItem() == item)
return i;
}
return -1;
}
public static void sendPacket(EntityPlayer player, int currentItem, int hash)
{
if (player instanceof EntityPlayerMP)
{
CarryOn.network.sendToAllAround(new CarrySlotPacket(currentItem, player.getEntityId(), hash), new TargetPoint(player.world.provider.getDimension(), player.posX, player.posY, player.posZ, 256));
CarryOn.network.sendTo(new CarrySlotPacket(currentItem, player.getEntityId(), hash), (EntityPlayerMP) player);
if (currentItem >= 9)
{
player.getEntityData().removeTag("carrySlot");
player.getEntityData().removeTag("overrideKey");
}
else
{
player.getEntityData().setInteger("carrySlot", currentItem);
if (hash != 0)
ScriptChecker.setCarryOnOverride(player, hash);
}
}
}
}

View File

@ -1,29 +1,28 @@
package tschipp.carryon.common.handler;
import java.lang.reflect.Method;
import java.util.UUID;
import javax.annotation.Nullable;
import net.darkhax.gamestages.GameStageHelper;
import net.darkhax.gamestages.data.IStageData;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import tschipp.carryon.CarryOn;
import tschipp.carryon.common.config.CarryOnConfig;
import tschipp.carryon.common.item.ItemTile;
@ -34,7 +33,8 @@ public class PickupHandler
{
public static boolean canPlayerPickUpBlock(EntityPlayer player, @Nullable TileEntity tile, World world, BlockPos pos)
{
{
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
@ -79,16 +79,48 @@ public class PickupHandler
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(state))
{
IStageData stageData = GameStageHelper.getPlayerData(player);
String condition = CustomPickupOverrideHandler.getPickupCondition(state);
if (stageData.hasStage(condition))
return true && handleProtections((EntityPlayerMP) player, world, pos, state);
try
{
Class<?> gameStageHelper = Class.forName("net.darkhax.gamestages.GameStageHelper");
Class<?> iStageData = Class.forName("net.darkhax.gamestages.data.IStageData");
Method getPlayerData = ReflectionHelper.findMethod(gameStageHelper, "getPlayerData", null, EntityPlayer.class);
Method hasStage = ReflectionHelper.findMethod(iStageData, "hasStage", null, String.class);
Object stageData = getPlayerData.invoke(null, player);
String condition = CustomPickupOverrideHandler.getPickupCondition(state);
boolean has = (boolean) hasStage.invoke(stageData, condition);
if (has)
return handleProtections((EntityPlayerMP) player, world, pos, state);
}
catch (Exception e)
{
try
{
Class<?> playerDataHandler = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler");
Class<?> iStageData = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler$IStageData");
Method getStageData = ReflectionHelper.findMethod(playerDataHandler, "getStageData", null, EntityPlayer.class);
Method hasUnlockedStage = ReflectionHelper.findMethod(iStageData, "hasUnlockedStage", null, String.class);
Object stageData = getStageData.invoke(null, player);
String condition = CustomPickupOverrideHandler.getPickupCondition(state);
boolean has = (boolean) hasUnlockedStage.invoke(stageData, condition);
if (has)
return handleProtections((EntityPlayerMP) player, world, pos, state);
}
catch (Exception ex)
{
return handleProtections((EntityPlayerMP) player, world, pos, state);
}
}
}
else if (CarryOnConfig.settings.pickupAllBlocks ? true : tile != null)
{
return true && handleProtections((EntityPlayerMP) player, world, pos, state);
return handleProtections((EntityPlayerMP) player, world, pos, state);
}
}
@ -113,8 +145,6 @@ public class PickupHandler
}
else
{
// check for allow babies to be picked up
if (toPickUp instanceof EntityAgeable && CarryOnConfig.settings.allowBabies)
{
EntityAgeable living = (EntityAgeable) toPickUp;
@ -134,10 +164,43 @@ public class PickupHandler
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(toPickUp))
{
IStageData stageData = GameStageHelper.getPlayerData(player);
String condition = CustomPickupOverrideHandler.getPickupCondition(toPickUp);
if (stageData.hasStage(condition))
return true && handleProtections((EntityPlayerMP) player, toPickUp);
try
{
Class<?> gameStageHelper = Class.forName("net.darkhax.gamestages.GameStageHelper");
Class<?> iStageData = Class.forName("net.darkhax.gamestages.data.IStageData");
Method getPlayerData = ReflectionHelper.findMethod(gameStageHelper, "getPlayerData", null, EntityPlayer.class);
Method hasStage = ReflectionHelper.findMethod(iStageData, "hasStage", null, String.class);
Object stageData = getPlayerData.invoke(null, player);
String condition = CustomPickupOverrideHandler.getPickupCondition(toPickUp);
boolean has = (boolean) hasStage.invoke(stageData, condition);
if (has)
return handleProtections((EntityPlayerMP) player, toPickUp);
}
catch (Exception e)
{
try
{
Class<?> playerDataHandler = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler");
Class<?> iStageData = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler$IStageData");
Method getStageData = ReflectionHelper.findMethod(playerDataHandler, "getStageData", null, EntityPlayer.class);
Method hasUnlockedStage = ReflectionHelper.findMethod(iStageData, "hasUnlockedStage", null, String.class);
Object stageData = getStageData.invoke(null, player);
String condition = CustomPickupOverrideHandler.getPickupCondition(toPickUp);
boolean has = (boolean) hasUnlockedStage.invoke(stageData, condition);
if (has)
return handleProtections((EntityPlayerMP) player, toPickUp);
}
catch (Exception ex)
{
return handleProtections((EntityPlayerMP) player, toPickUp);
}
}
}
else
return true && handleProtections((EntityPlayerMP) player, toPickUp);
@ -179,14 +242,49 @@ public class PickupHandler
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(toPickUp))
{
IStageData stageData = GameStageHelper.getPlayerData(player);
String condition = CustomPickupOverrideHandler.getPickupCondition(toPickUp);
if (stageData.hasStage(condition))
return true && handleProtections((EntityPlayerMP) player, toPickUp);
try
{
Class<?> gameStageHelper = Class.forName("net.darkhax.gamestages.GameStageHelper");
Class<?> iStageData = Class.forName("net.darkhax.gamestages.data.IStageData");
Method getPlayerData = ReflectionHelper.findMethod(gameStageHelper, "getPlayerData", null, EntityPlayer.class);
Method hasStage = ReflectionHelper.findMethod(iStageData, "hasStage", null, String.class);
Object stageData = getPlayerData.invoke(null, player);
String condition = CustomPickupOverrideHandler.getPickupCondition(toPickUp);
boolean has = (boolean) hasStage.invoke(stageData, condition);
if (has)
return handleProtections((EntityPlayerMP) player, toPickUp);
}
catch (Exception e)
{
try
{
Class<?> playerDataHandler = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler");
Class<?> iStageData = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler$IStageData");
Method getStageData = ReflectionHelper.findMethod(playerDataHandler, "getStageData", null, EntityPlayer.class);
Method hasUnlockedStage = ReflectionHelper.findMethod(iStageData, "hasUnlockedStage", null, String.class);
Object stageData = getStageData.invoke(null, player);
String condition = CustomPickupOverrideHandler.getPickupCondition(toPickUp);
boolean has = (boolean) hasUnlockedStage.invoke(stageData, condition);
if (has)
return handleProtections((EntityPlayerMP) player, toPickUp);
}
catch (Exception ex)
{
return handleProtections((EntityPlayerMP) player, toPickUp);
}
}
}
else
return true && handleProtections((EntityPlayerMP) player, toPickUp);
}
}
}
@ -203,12 +301,12 @@ public class PickupHandler
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, player);
MinecraftForge.EVENT_BUS.post(event);
if(event.isCanceled())
if (event.isCanceled())
breakable = false;
return breakable;
}
private static boolean handleProtections(EntityPlayerMP player, Entity entity)
{
boolean canPickup = true;
@ -216,9 +314,9 @@ public class PickupHandler
AttackEntityEvent event = new AttackEntityEvent(player, entity);
MinecraftForge.EVENT_BUS.post(event);
if(event.isCanceled())
if (event.isCanceled())
canPickup = false;
return canPickup;
}

View File

@ -27,6 +27,7 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
import tschipp.carryon.CarryOn;
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
import tschipp.carryon.common.config.CarryOnConfig;
import tschipp.carryon.common.event.ItemEvents;
import tschipp.carryon.network.client.CarrySlotPacket;
public class ItemEntity extends Item
@ -120,7 +121,8 @@ public class ItemEntity extends Item
}
clearEntityData(stack);
player.setHeldItem(hand, ItemStack.EMPTY);
CarryOn.network.sendToAllAround(new CarrySlotPacket(9, player.getEntityId()), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256));
ItemEvents.sendPacket(player, 9, 0);
}
player.getEntityData().removeTag("overrideKey");
return EnumActionResult.SUCCESS;

View File

@ -3,6 +3,7 @@ package tschipp.carryon.common.item;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
@ -11,7 +12,6 @@ import net.minecraft.block.BlockStairs;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@ -32,21 +32,20 @@ import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.ClickEvent.Action;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import tschipp.carryon.CarryOn;
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
import tschipp.carryon.common.config.CarryOnConfig;
import tschipp.carryon.common.event.ItemEvents;
import tschipp.carryon.common.handler.CustomPickupOverrideHandler;
import tschipp.carryon.common.handler.ModelOverridesHandler;
import tschipp.carryon.network.client.CarrySlotPacket;
public class ItemTile extends Item
{
public static final String TILE_DATA_KEY = "tileData";
public static final String[] FACING_KEYS = new String[] { "rotation", "rot", "facing", "face", "direction", "dir", "front" };
public ItemTile()
{
@ -86,13 +85,12 @@ public class ItemTile extends Item
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if(Loader.isModLoaded("betterplacement"))
if (Loader.isModLoaded("betterplacement"))
{
if(CarryOnKeybinds.isKeyPressed(player))
if (CarryOnKeybinds.isKeyPressed(player))
return EnumActionResult.FAIL;
}
Block block = world.getBlockState(pos).getBlock();
ItemStack stack = player.getHeldItem(hand);
if (hasTileData(stack))
@ -120,6 +118,7 @@ public class ItemTile extends Item
{
boolean set = false;
// Handles Blockstate rotation
Iterator<IProperty<?>> iterator = containedblock.getDefaultState().getPropertyKeys().iterator();
while (iterator.hasNext())
{
@ -137,7 +136,41 @@ public class ItemTile extends Item
world.setBlockState(pos2, containedstate.withProperty(prop, facing2.getOpposite()));
set = true;
}
}
// If the blockstate doesn't handle rotation, try to
// change rotation via NBT
if (!set && !getTileData(stack).hasNoTags())
{
NBTTagCompound tag = getTileData(stack);
Set<String> keys = tag.getKeySet();
keytester:
for (String key : keys)
{
for (String facingKey : FACING_KEYS)
{
if (key.toLowerCase().equals(facingKey))
{
String type = tag.getTagTypeName(tag.getTagId(key));
switch (type)
{
case "TAG_String":
tag.setString(key, facing2.getOpposite().getName());
break;
case "TAG_Int":
tag.setInteger(key, facing2.getOpposite().getIndex());
break;
case "TAG_Byte":
tag.setByte(key, (byte) facing2.getOpposite().getIndex());
break;
default:
break;
}
break keytester;
}
}
}
}
if (!set)
@ -153,7 +186,7 @@ public class ItemTile extends Item
player.playSound(containedblock.getSoundType().getPlaceSound(), 1.0f, 0.5f);
player.setHeldItem(hand, ItemStack.EMPTY);
player.getEntityData().removeTag("overrideKey");
CarryOn.network.sendToAllAround(new CarrySlotPacket(9, player.getEntityId()), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256));
ItemEvents.sendPacket(player, 9, 0);
return EnumActionResult.SUCCESS;
}

View File

@ -41,6 +41,11 @@ public class CarryOnOverride
private boolean renderLeftArm = true;
private boolean renderRightArm = true;
//EFFECTS
private String commandInit;
private String commandLoop;
private String commandPlace;
private boolean isBlock;
private boolean isEntity;
private final String path;
@ -51,6 +56,28 @@ public class CarryOnOverride
this.path = path;
}
public String getCommandInit()
{
return commandInit;
}
public void setCommandInit(String commandInit)
{
this.commandInit = commandInit;
}
public String getCommandLoop()
{
return commandLoop;
}
public void setCommandLoop(String commandLoop)
{
this.commandLoop = commandLoop;
}
public String getConditionEffects()
{
return conditionEffects;
@ -115,7 +142,7 @@ public class CarryOnOverride
{
return "Code: " + this.hashCode();
}
@Override
public boolean equals(Object obj)
{
@ -126,6 +153,27 @@ public class CarryOnOverride
if (getClass() != obj.getClass())
return false;
CarryOnOverride other = (CarryOnOverride) obj;
if (commandInit == null)
{
if (other.commandInit != null)
return false;
}
else if (!commandInit.equals(other.commandInit))
return false;
if (commandLoop == null)
{
if (other.commandLoop != null)
return false;
}
else if (!commandLoop.equals(other.commandLoop))
return false;
if (commandPlace == null)
{
if (other.commandPlace != null)
return false;
}
else if (!commandPlace.equals(other.commandPlace))
return false;
if (conditionAchievement == null)
{
if (other.conditionAchievement != null)
@ -133,6 +181,13 @@ public class CarryOnOverride
}
else if (!conditionAchievement.equals(other.conditionAchievement))
return false;
if (conditionEffects == null)
{
if (other.conditionEffects != null)
return false;
}
else if (!conditionEffects.equals(other.conditionEffects))
return false;
if (conditionGamemode == null)
{
if (other.conditionGamemode != null)
@ -172,6 +227,15 @@ public class CarryOnOverride
return false;
if (isEntity != other.isEntity)
return false;
if (path == null)
{
if (other.path != null)
return false;
}
else if (!path.equals(other.path))
return false;
if (renderLeftArm != other.renderLeftArm)
return false;
if (renderMeta != other.renderMeta)
return false;
if (renderNBT == null)
@ -195,6 +259,8 @@ public class CarryOnOverride
}
else if (!renderNameEntity.equals(other.renderNameEntity))
return false;
if (renderRightArm != other.renderRightArm)
return false;
if (renderRotation == null)
{
if (other.renderRotation != null)
@ -310,6 +376,8 @@ public class CarryOnOverride
return true;
}
public boolean isBlock()
{
return isBlock;
@ -570,4 +638,18 @@ public class CarryOnOverride
this.renderScale = renderScale;
}
public String getCommandPlace()
{
return commandPlace;
}
public void setCommandPlace(String commandPlace)
{
this.commandPlace = commandPlace;
}
}

View File

@ -1,8 +1,9 @@
package tschipp.carryon.common.scripting;
import java.lang.reflect.Method;
import javax.annotation.Nullable;
import net.darkhax.gamestages.GameStageHelper;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementManager;
import net.minecraft.block.Block;
@ -19,6 +20,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import tschipp.carryon.common.config.CarryOnConfig;
import tschipp.carryon.common.helper.ScriptParseHelper;
@ -99,17 +101,56 @@ public class ScriptChecker
public static boolean fulfillsConditions(CarryOnOverride override, EntityPlayer player)
{
AdvancementManager manager = ((WorldServer)((EntityPlayerMP)player).world).getAdvancementManager();
AdvancementManager manager = ((WorldServer) ((EntityPlayerMP) player).world).getAdvancementManager();
Advancement adv = manager.getAdvancement(new ResourceLocation((override.getConditionAchievement()) == null ? "" : override.getConditionAchievement()));
boolean achievement = adv == null ? true : ((EntityPlayerMP)player).getAdvancements().getProgress(adv).isDone();
boolean achievement = adv == null ? true : ((EntityPlayerMP) player).getAdvancements().getProgress(adv).isDone();
boolean gamemode = ScriptParseHelper.matches(((EntityPlayerMP) player).interactionManager.getGameType().getID(), override.getConditionGamemode());
boolean gamestage = Loader.isModLoaded("gamestages") ? (override.getConditionGamestage() != null ? GameStageHelper.getPlayerData(player).hasStage(override.getConditionGamestage()) : true) : true;
boolean gamestage = true;
if (Loader.isModLoaded("gamestages"))
{
if (override.getConditionGamestage() != null)
{
try
{
Class<?> gameStageHelper = Class.forName("net.darkhax.gamestages.GameStageHelper");
Class<?> iStageData = Class.forName("net.darkhax.gamestages.data.IStageData");
Method getPlayerData = ReflectionHelper.findMethod(gameStageHelper, "getPlayerData", null, EntityPlayer.class);
Method hasStage = ReflectionHelper.findMethod(iStageData, "hasStage", null, String.class);
Object stageData = getPlayerData.invoke(null, player);
String condition = override.getConditionGamestage();
gamestage = (boolean) hasStage.invoke(stageData, condition);
}
catch (Exception e)
{
try
{
Class<?> playerDataHandler = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler");
Class<?> iStageData = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler$IStageData");
Method getStageData = ReflectionHelper.findMethod(playerDataHandler, "getStageData", null, EntityPlayer.class);
Method hasUnlockedStage = ReflectionHelper.findMethod(iStageData, "hasUnlockedStage", null, String.class);
Object stageData = getStageData.invoke(null, player);
String condition = override.getConditionGamestage();
gamestage = (boolean) hasUnlockedStage.invoke(stageData, condition);
}
catch (Exception ex)
{
}
}
}
}
boolean position = ScriptParseHelper.matches(player.getPosition(), override.getConditionPosition());
boolean xp = ScriptParseHelper.matches(player.experienceLevel, override.getConditionXp());
boolean scoreboard = ScriptParseHelper.matchesScore(player, override.getConditionScoreboard());
boolean effects = ScriptParseHelper.hasEffects(player, override.getConditionEffects());
return (achievement && gamemode && gamestage && position && xp && scoreboard && effects);
}
@ -121,13 +162,13 @@ public class ScriptChecker
if (tag != null && tag.hasKey("overrideKey"))
{
int key = tag.getInteger("overrideKey");
return ScriptReader.OVERRIDES.get(key);
}
return null;
}
public static void setCarryOnOverride(EntityPlayer player, int i)
{
NBTTagCompound tag = player.getEntityData();
@ -135,5 +176,5 @@ public class ScriptChecker
if (tag != null)
tag.setInteger("overrideKey", i);
}
}

View File

@ -57,8 +57,9 @@ public class ScriptReader
JsonObject object = (JsonObject) json.get("object");
JsonObject conditions = (JsonObject) json.get("conditions");
JsonObject render = (JsonObject) json.get("render");
JsonObject effects = (JsonObject) json.get("effects");
if ((object != null && conditions != null) || (object != null && render != null))
if ((object != null && conditions != null) || (object != null && render != null) || (object != null && effects != null))
{
JsonObject block = (JsonObject) object.get("block");
JsonObject entity = (JsonObject) object.get("entity");
@ -122,7 +123,7 @@ public class ScriptReader
JsonElement gamemode = conditions.get("gamemode");
JsonElement scoreboard = conditions.get("scoreboard");
JsonElement position = conditions.get("position");
JsonElement effects = conditions.get("effects");
JsonElement potionEffects = conditions.get("effects");
if(gamestage != null)
override.setConditionGamestage(gamestage.getAsString());
@ -136,8 +137,8 @@ public class ScriptReader
override.setConditionScoreboard(scoreboard.getAsString());
if(position != null)
override.setConditionPosition(position.getAsString());
if(effects != null)
override.setConditionEffects(effects.getAsString());
if(potionEffects != null)
override.setConditionEffects(potionEffects.getAsString());
}
if (render != null)
@ -178,8 +179,21 @@ public class ScriptReader
override.setRenderRightArm(renderRightArm.getAsBoolean());
}
OVERRIDES.put(override.hashCode(), override);
if(effects != null)
{
JsonElement commandInit = effects.get("commandPickup");
JsonElement commandLoop = effects.get("commandLoop");
JsonElement commandPlace = effects.get("commandPlace");
if(commandInit != null)
override.setCommandInit(commandInit.getAsString());
if(commandLoop != null)
override.setCommandLoop(commandLoop.getAsString());
if(commandPlace != null)
override.setCommandPlace(commandPlace.getAsString());
}
OVERRIDES.put(override.hashCode(), override);
}
}
}

View File

@ -2,7 +2,7 @@
{
"modid" : "carryon",
"name" : "Carry On",
"version" : "1.9.2", "mcversion" : "1.12.2",
"version" : "1.10", "mcversion" : "1.12.2",
"url" : "",
"credits" : "Tschipp, Purplicious_Cow, cy4n",
"authorList" : ["Tschipp, Purplicious_Cow, cy4n"],