From 1231bb02ac051592696c432bb7489040bb5bff3b Mon Sep 17 00:00:00 2001 From: Purplicious_Cow Date: Sat, 31 Mar 2018 23:35:40 +0200 Subject: [PATCH 1/5] Add mob stacking into 1.11 --- .../carryon/common/config/Configs.java | 9 ++ .../common/event/ItemEntityEvents.java | 89 ++++++++++++++++++- 2 files changed, 97 insertions(+), 1 deletion(-) diff --git a/src/main/java/tschipp/carryon/common/config/Configs.java b/src/main/java/tschipp/carryon/common/config/Configs.java index 911017e..4cfb8a3 100644 --- a/src/main/java/tschipp/carryon/common/config/Configs.java +++ b/src/main/java/tschipp/carryon/common/config/Configs.java @@ -64,6 +64,15 @@ public class Configs { @Config.RequiresMcRestart() @Comment("Use custom Pickup Scripts. Having this set to false, will not allow you to run scripts, but will save you some performance") public boolean useScripts=false; + + @Comment("Allows entities to be stacked using Carry On") + public boolean stackableEntities = true; + + @Comment("Maximum stack limit for entities") + public int maxEntityStackLimit = 20; + + @Comment("Whether entities size matters when stacking or not") + public boolean entitySizeMattersStacking = true; } public static class WhiteList diff --git a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java b/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java index 1cc5df2..102ffe2 100644 --- a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java +++ b/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java @@ -1,16 +1,23 @@ package tschipp.carryon.common.event; +import java.util.List; + +import com.google.common.collect.Lists; + import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.passive.EntityAnimal; +import net.minecraft.entity.passive.EntityHorse; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.SoundEvents; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; +import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.event.entity.EntityJoinWorldEvent; @@ -24,6 +31,7 @@ import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import tschipp.carryon.CarryOn; import tschipp.carryon.client.keybinds.CarryOnKeybinds; +import tschipp.carryon.common.config.CarryOnConfig; import tschipp.carryon.common.handler.PickupHandler; import tschipp.carryon.common.handler.RegistrationHandler; import tschipp.carryon.common.item.ItemEntity; @@ -34,6 +42,9 @@ import tschipp.carryon.network.client.CarrySlotPacket; public class ItemEntityEvents { + + private final List riddenByEntities = Lists.newArrayList(); + @SubscribeEvent(priority = EventPriority.HIGH) public void onBlockClick(PlayerInteractEvent.RightClickBlock event) { @@ -91,7 +102,7 @@ public class ItemEntityEvents { if(entity instanceof EntityAnimal) ((EntityAnimal) entity).clearLeashed(true, true); - + if (PickupHandler.canPlayerPickUpEntity(player, entity)) { if (ItemEntity.storeEntityData(entity, world, stack)) @@ -118,7 +129,83 @@ public class ItemEntityEvents } } + } else if (!main.isEmpty() && main.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(main) && CarryOnKeybinds.isKeyPressed(player) && CarryOnConfig.settings.stackableEntities) { + + + Entity entityHeld = ItemEntity.getEntity(main, world); + + if (entity.hurtResistantTime == 0 && entityHeld instanceof EntityLivingBase) { + + if (!world.isRemote && entityHeld.getUniqueID() != entity.getUniqueID() && !entityHeld.isDead && !entity.isDead) { + + //if no riders + if (!entity.isBeingRidden()) { + //Tame Horse so it doens't buck rider + if (entity instanceof EntityHorse) { + EntityHorse horse = (EntityHorse) entity; + horse.setHorseTamed(true); + } + double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ); + + //if too close, change position (and back) to bypass protected canBeRidden + if (distance < 6) { + double tempX = entity.posX; + double tempY = entity.posY; + double tempZ = entity.posZ; + entity.setPosition(tempX, tempY + 2.6, tempZ); + world.spawnEntity(entityHeld); + entityHeld.startRiding(entity, false); + entityHeld.setPositionAndUpdate(tempX, tempY, tempZ); + } else { + world.spawnEntity(entityHeld); + entityHeld.startRiding(entity, false); + } + + //if multiple riders, loop through and add next to top (elevator style) + } else { + Entity entityTry = entity.getPassengers().get(0); + int tempLimit = CarryOnConfig.settings.maxEntityStackLimit; + + //force limit to prevent crash + if (tempLimit < 0) { + tempLimit = 1; + } + for (int i = 0; i <= tempLimit; i++) { + + if (entityTry.isBeingRidden()) { + entityTry = entityTry.getPassengers().get(0); + } else { + break; + } + } + + double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ); + if (distance < 6) { + double tempX = entity.posX; + double tempY = entity.posY; + double tempZ = entity.posZ; + entity.setPosition(tempX, tempY + 2.6, tempZ); + world.spawnEntity(entityHeld); + if (entityTry != null) { + entityHeld.startRiding(entityTry, false); + entityHeld.setPositionAndUpdate(tempX, tempY, tempZ); + } + } else { + world.spawnEntity(entityHeld); + entityHeld.startRiding(entityTry, false); + } + } + + world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_HORSE_SADDLE, SoundCategory.PLAYERS, 0.5F, 1.5F); + 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)); + event.setCanceled(true); + } + } + } + } } From 5bd299a9d189ecb0a8e2db529853ac0107117608 Mon Sep 17 00:00:00 2001 From: Purplicious_Cow Date: Wed, 4 Apr 2018 08:14:52 +0200 Subject: [PATCH 2/5] Added size-based stacking rule/config and fail sound into 1.11 --- .../carryon/common/config/Configs.java | 2 +- .../common/event/ItemEntityEvents.java | 69 ++++++++++++------- 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/main/java/tschipp/carryon/common/config/Configs.java b/src/main/java/tschipp/carryon/common/config/Configs.java index 4cfb8a3..d85eeda 100644 --- a/src/main/java/tschipp/carryon/common/config/Configs.java +++ b/src/main/java/tschipp/carryon/common/config/Configs.java @@ -71,7 +71,7 @@ public class Configs { @Comment("Maximum stack limit for entities") public int maxEntityStackLimit = 20; - @Comment("Whether entities size matters when stacking or not") + @Comment("Whether entities' size matters when stacking or not") public boolean entitySizeMattersStacking = true; } diff --git a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java b/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java index 102ffe2..61dac34 100644 --- a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java +++ b/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java @@ -10,6 +10,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.passive.EntityHorse; +import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.SoundEvents; @@ -133,39 +134,47 @@ public class ItemEntityEvents Entity entityHeld = ItemEntity.getEntity(main, world); - + if (entity.hurtResistantTime == 0 && entityHeld instanceof EntityLivingBase) { if (!world.isRemote && entityHeld.getUniqueID() != entity.getUniqueID() && !entityHeld.isDead && !entity.isDead) { + double sizeEntity = entity.height * entity.width; + double sizeHeldEntity = entityHeld.height * entityHeld.width; //if no riders if (!entity.isBeingRidden()) { - //Tame Horse so it doens't buck rider - if (entity instanceof EntityHorse) { - EntityHorse horse = (EntityHorse) entity; - horse.setHorseTamed(true); - } - double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ); - - //if too close, change position (and back) to bypass protected canBeRidden - if (distance < 6) { - double tempX = entity.posX; - double tempY = entity.posY; - double tempZ = entity.posZ; - entity.setPosition(tempX, tempY + 2.6, tempZ); - world.spawnEntity(entityHeld); - entityHeld.startRiding(entity, false); - entityHeld.setPositionAndUpdate(tempX, tempY, tempZ); + //if entity size matters in stacking + if ((CarryOnConfig.settings.entitySizeMattersStacking && sizeHeldEntity <= sizeEntity) || !CarryOnConfig.settings.entitySizeMattersStacking) { + //Tame Horse so it doens't buck rider + if (entity instanceof EntityHorse) { + EntityHorse horse = (EntityHorse) entity; + horse.setHorseTamed(true); + } + double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ); + + //if too close, change position (and back) to bypass protected canBeRidden + if (distance < 6) { + double tempX = entity.posX; + double tempY = entity.posY; + double tempZ = entity.posZ; + entity.setPosition(tempX, tempY + 2.6, tempZ); + world.spawnEntity(entityHeld); + entityHeld.startRiding(entity, false); + entityHeld.setPositionAndUpdate(tempX, tempY, tempZ); + } else { + world.spawnEntity(entityHeld); + entityHeld.startRiding(entity, false); + } } else { + world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_BASS, SoundCategory.PLAYERS, 0.5F, 1.5F); world.spawnEntity(entityHeld); - entityHeld.startRiding(entity, false); } - //if multiple riders, loop through and add next to top (elevator style) + //if multiple riders, loop through and add next to top (elevator style) } else { Entity entityTry = entity.getPassengers().get(0); int tempLimit = CarryOnConfig.settings.maxEntityStackLimit; - + //force limit to prevent crash if (tempLimit < 0) { tempLimit = 1; @@ -187,16 +196,28 @@ public class ItemEntityEvents entity.setPosition(tempX, tempY + 2.6, tempZ); world.spawnEntity(entityHeld); if (entityTry != null) { - entityHeld.startRiding(entityTry, false); - entityHeld.setPositionAndUpdate(tempX, tempY, tempZ); + //if entity size matters in stacking + if ((CarryOnConfig.settings.entitySizeMattersStacking && sizeHeldEntity <= sizeEntity) || !CarryOnConfig.settings.entitySizeMattersStacking) { + entityHeld.startRiding(entityTry, false); + entityHeld.setPositionAndUpdate(tempX, tempY, tempZ); + } else { + world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_BASS, SoundCategory.PLAYERS, 0.5F, 1.5F); + } } } else { world.spawnEntity(entityHeld); - entityHeld.startRiding(entityTry, false); + if ((CarryOnConfig.settings.entitySizeMattersStacking && sizeHeldEntity <= sizeEntity) || !CarryOnConfig.settings.entitySizeMattersStacking) { + entityHeld.startRiding(entityTry, false); + } else { + world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_BASS, SoundCategory.PLAYERS, 0.5F, 1.5F); + } } } - world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_HORSE_SADDLE, SoundCategory.PLAYERS, 0.5F, 1.5F); + if ((CarryOnConfig.settings.entitySizeMattersStacking && sizeHeldEntity <= sizeEntity) || !CarryOnConfig.settings.entitySizeMattersStacking) { + world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_HORSE_SADDLE, SoundCategory.PLAYERS, 0.5F, 1.5F); + } + 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)); From a8deaee1e82a598deed46900277f6fd14f0264cf Mon Sep 17 00:00:00 2001 From: David Vierra Date: Tue, 1 May 2018 04:43:46 -1000 Subject: [PATCH 3/5] Blacklist Astral Sorcery blocks Astral Sorcery has a mechanic called the "starlight network" which misbehaves when tiles are unexpectedly moved or removed. For this reason, AS blocks are also banned from Blood Magic teleposers. --- src/main/java/tschipp/carryon/common/config/Configs.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/tschipp/carryon/common/config/Configs.java b/src/main/java/tschipp/carryon/common/config/Configs.java index d85eeda..82e3ab4 100644 --- a/src/main/java/tschipp/carryon/common/config/Configs.java +++ b/src/main/java/tschipp/carryon/common/config/Configs.java @@ -116,6 +116,7 @@ public class Configs { "tconstruct:*", "rustic:*", "botania:*", + "astralsorcery:*", "quark:colored_bed_*", "immersiveengineering:*", "embers:block_furnace", From 77e0816646c3f938396be854180de7a98bb39fb9 Mon Sep 17 00:00:00 2001 From: Tschipp Date: Fri, 11 May 2018 20:04:16 +0200 Subject: [PATCH 4/5] Fixed #91, #93, #94, #95, #96, #100, #101, added Mob Stacking --- src/main/java/tschipp/carryon/CarryOn.java | 2 +- .../carryon/common/config/Configs.java | 8 +- .../common/event/ItemEntityEvents.java | 158 +++++++++--------- .../carryon/common/event/ItemEvents.java | 32 +++- 4 files changed, 117 insertions(+), 83 deletions(-) diff --git a/src/main/java/tschipp/carryon/CarryOn.java b/src/main/java/tschipp/carryon/CarryOn.java index e92cfda..81f666a 100644 --- a/src/main/java/tschipp/carryon/CarryOn.java +++ b/src/main/java/tschipp/carryon/CarryOn.java @@ -34,7 +34,7 @@ public class CarryOn { public static CarryOn instance; public static final String MODID = "carryon"; - public static final String VERSION = "1.8"; + public static final String VERSION = "1.9"; public static final String NAME = "Carry On"; public static final String ACCEPTED_VERSIONS = "[1.11,1.12)"; public static final String UPDATE_JSON = "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/"; diff --git a/src/main/java/tschipp/carryon/common/config/Configs.java b/src/main/java/tschipp/carryon/common/config/Configs.java index d85eeda..72f5d47 100644 --- a/src/main/java/tschipp/carryon/common/config/Configs.java +++ b/src/main/java/tschipp/carryon/common/config/Configs.java @@ -62,14 +62,15 @@ public class Configs { public boolean dropCarriedWhenHit=false; @Config.RequiresMcRestart() - @Comment("Use custom Pickup Scripts. Having this set to false, will not allow you to run scripts, but will save you some performance") + @Comment("Use custom Pickup Scripts. Having this set to false, will not allow you to run scripts, but will increase your performance") public boolean useScripts=false; @Comment("Allows entities to be stacked using Carry On") public boolean stackableEntities = true; + @Config.RangeInt(min = 1) @Comment("Maximum stack limit for entities") - public int maxEntityStackLimit = 20; + public int maxEntityStackLimit = 10; @Comment("Whether entities' size matters when stacking or not") public boolean entitySizeMattersStacking = true; @@ -107,6 +108,8 @@ public class Configs { "minecraft:jungle_door", "minecraft:acacia_door", "minecraft:dark_oak_door", + "minecraft:waterlily", + "minecraft:cake", "animania:block_trough", "animania:block_invisiblock", "colossalchests:*", @@ -135,6 +138,7 @@ public class Configs { "skyresources:*", "lootbags:*", "exsartagine:*", + "aquamunda:tank" }; diff --git a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java b/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java index 61dac34..f844549 100644 --- a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java +++ b/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java @@ -43,9 +43,6 @@ import tschipp.carryon.network.client.CarrySlotPacket; public class ItemEntityEvents { - - private final List riddenByEntities = Lists.newArrayList(); - @SubscribeEvent(priority = EventPriority.HIGH) public void onBlockClick(PlayerInteractEvent.RightClickBlock event) { @@ -101,7 +98,7 @@ public class ItemEntityEvents if (entity.hurtResistantTime == 0) { - if(entity instanceof EntityAnimal) + if (entity instanceof EntityAnimal) ((EntityAnimal) entity).clearLeashed(true, true); if (PickupHandler.canPlayerPickUpEntity(player, entity)) @@ -130,107 +127,110 @@ public class ItemEntityEvents } } - } else if (!main.isEmpty() && main.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(main) && CarryOnKeybinds.isKeyPressed(player) && CarryOnConfig.settings.stackableEntities) { - - + } + else if (!main.isEmpty() && main.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(main) && !CarryOnKeybinds.isKeyPressed(player) && CarryOnConfig.settings.stackableEntities) + { Entity entityHeld = ItemEntity.getEntity(main, world); - if (entity.hurtResistantTime == 0 && entityHeld instanceof EntityLivingBase) { + if (entity.hurtResistantTime == 0 && entityHeld instanceof EntityLivingBase) + { - if (!world.isRemote && entityHeld.getUniqueID() != entity.getUniqueID() && !entityHeld.isDead && !entity.isDead) { + if (!world.isRemote && entityHeld.getUniqueID() != entity.getUniqueID() && !entityHeld.isDead && !entity.isDead) + { - double sizeEntity = entity.height * entity.width; double sizeHeldEntity = entityHeld.height * entityHeld.width; - //if no riders - if (!entity.isBeingRidden()) { - //if entity size matters in stacking - if ((CarryOnConfig.settings.entitySizeMattersStacking && sizeHeldEntity <= sizeEntity) || !CarryOnConfig.settings.entitySizeMattersStacking) { - //Tame Horse so it doens't buck rider - if (entity instanceof EntityHorse) { - EntityHorse horse = (EntityHorse) entity; + double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ); + Entity lowestEntity = entity.getLowestRidingEntity(); + int numPassengers = getAllPassengers(lowestEntity); + if (numPassengers < CarryOnConfig.settings.maxEntityStackLimit - 1) + { + Entity topEntity = getTopPassenger(lowestEntity); + + double sizeEntity = topEntity.height * topEntity.width; + if ((CarryOnConfig.settings.entitySizeMattersStacking && sizeHeldEntity <= sizeEntity) || !CarryOnConfig.settings.entitySizeMattersStacking) + { + if (topEntity instanceof EntityHorse) + { + EntityHorse horse = (EntityHorse) topEntity; horse.setHorseTamed(true); } - double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ); - - //if too close, change position (and back) to bypass protected canBeRidden - if (distance < 6) { + + if (distance < 6) + { double tempX = entity.posX; double tempY = entity.posY; double tempZ = entity.posZ; - entity.setPosition(tempX, tempY + 2.6, tempZ); + entityHeld.setPosition(tempX, tempY + 2.6, tempZ); world.spawnEntity(entityHeld); - entityHeld.startRiding(entity, false); + entityHeld.startRiding(topEntity, false); entityHeld.setPositionAndUpdate(tempX, tempY, tempZ); - } else { + } + else + { + entityHeld.setPosition(entity.posX, entity.posY, entity.posZ); world.spawnEntity(entityHeld); - entityHeld.startRiding(entity, false); + entityHeld.startRiding(topEntity, false); } - } else { + + + 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)); + event.setCanceled(true); + world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_HORSE_SADDLE, SoundCategory.PLAYERS, 0.5F, 1.5F); + } + else + { world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_BASS, SoundCategory.PLAYERS, 0.5F, 1.5F); - world.spawnEntity(entityHeld); - } - - //if multiple riders, loop through and add next to top (elevator style) - } else { - Entity entityTry = entity.getPassengers().get(0); - int tempLimit = CarryOnConfig.settings.maxEntityStackLimit; - - //force limit to prevent crash - if (tempLimit < 0) { - tempLimit = 1; - } - for (int i = 0; i <= tempLimit; i++) { - - if (entityTry.isBeingRidden()) { - entityTry = entityTry.getPassengers().get(0); - } else { - break; - } - } - - double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ); - if (distance < 6) { - double tempX = entity.posX; - double tempY = entity.posY; - double tempZ = entity.posZ; - entity.setPosition(tempX, tempY + 2.6, tempZ); - world.spawnEntity(entityHeld); - if (entityTry != null) { - //if entity size matters in stacking - if ((CarryOnConfig.settings.entitySizeMattersStacking && sizeHeldEntity <= sizeEntity) || !CarryOnConfig.settings.entitySizeMattersStacking) { - entityHeld.startRiding(entityTry, false); - entityHeld.setPositionAndUpdate(tempX, tempY, tempZ); - } else { - world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_BASS, SoundCategory.PLAYERS, 0.5F, 1.5F); - } - } - } else { - world.spawnEntity(entityHeld); - if ((CarryOnConfig.settings.entitySizeMattersStacking && sizeHeldEntity <= sizeEntity) || !CarryOnConfig.settings.entitySizeMattersStacking) { - entityHeld.startRiding(entityTry, false); - } else { - world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_BASS, SoundCategory.PLAYERS, 0.5F, 1.5F); - } + return; } } - - if ((CarryOnConfig.settings.entitySizeMattersStacking && sizeHeldEntity <= sizeEntity) || !CarryOnConfig.settings.entitySizeMattersStacking) { - world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_HORSE_SADDLE, SoundCategory.PLAYERS, 0.5F, 1.5F); + else + { + world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_BASS, SoundCategory.PLAYERS, 0.5F, 1.5F); + return; } - - 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)); - event.setCanceled(true); } + } } - } } + public static int getAllPassengers(Entity entity) + { + int passengers = 0; + while (entity.isBeingRidden()) + { + List pass = entity.getPassengers(); + if (!pass.isEmpty()) + { + entity = pass.get(0); + passengers++; + } + } + + return passengers; + } + + public static Entity getTopPassenger(Entity entity) + { + Entity top = entity; + while (entity.isBeingRidden()) + { + List pass = entity.getPassengers(); + if (!pass.isEmpty()) + { + entity = pass.get(0); + top = entity; + } + } + + return top; + } + @SubscribeEvent public void onLivingUpdate(LivingUpdateEvent event) { diff --git a/src/main/java/tschipp/carryon/common/event/ItemEvents.java b/src/main/java/tschipp/carryon/common/event/ItemEvents.java index f5f7b97..d31bd2b 100644 --- a/src/main/java/tschipp/carryon/common/event/ItemEvents.java +++ b/src/main/java/tschipp/carryon/common/event/ItemEvents.java @@ -33,6 +33,8 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent; import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; import tschipp.carryon.CarryOn; import tschipp.carryon.client.keybinds.CarryOnKeybinds; import tschipp.carryon.common.config.CarryOnConfig; @@ -261,7 +263,7 @@ public class ItemEvents try { CarryOn.network.sendToAllAround(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId(), overrideHash), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256)); - world.removeTileEntity(pos); + emptyTileEntity(te); world.setBlockToAir(pos); player.setHeldItem(EnumHand.MAIN_HAND, stack); event.setUseBlock(Result.DENY); @@ -269,6 +271,7 @@ public class ItemEvents } catch (Exception e) { + e.printStackTrace(); CarryOn.network.sendToAllAround(new CarrySlotPacket(9, player.getEntityId()), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256)); world.setBlockState(pos, statee); if (!tag.hasNoTags()) @@ -287,6 +290,33 @@ public class ItemEvents } } } + + public static void emptyTileEntity(TileEntity te) + { + if (te != null && !te.isInvalid()) + { + for (EnumFacing facing : EnumFacing.VALUES) + { + if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)) + { + IItemHandler itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing); + for (int i = 0; i < itemHandler.getSlots(); i++) + { + itemHandler.extractItem(i, 64, false); + } + } + } + + if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) + { + IItemHandler itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); + for (int i = 0; i < itemHandler.getSlots(); i++) + { + itemHandler.extractItem(i, 64, false); + } + } + } + } @SubscribeEvent public void onRespawn(PlayerEvent.Clone event) From faea11d4845177191ffb7e523c7b8e6de9294289 Mon Sep 17 00:00:00 2001 From: Tschipp Date: Fri, 11 May 2018 20:15:39 +0200 Subject: [PATCH 5/5] Mcmod.info [1.11.2] --- src/main/resources/mcmod.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index a824278..d4d44cd 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -2,7 +2,7 @@ { "modid" : "carryon", "name" : "Carry On", - "version" : "1.8", "mcversion" : "1.11.2", + "version" : "1.9", "mcversion" : "1.11.2", "url" : "", "credits" : "Tschipp, Purplicious_Cow, cy4n", "authorList" : ["Tschipp, Purplicious_Cow, cy4n"],