diff --git a/src/main/java/tschipp/carryon/CarryOn.java b/src/main/java/tschipp/carryon/CarryOn.java index 5131f0c..dd1e869 100644 --- a/src/main/java/tschipp/carryon/CarryOn.java +++ b/src/main/java/tschipp/carryon/CarryOn.java @@ -32,7 +32,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.12.2,1.13)"; 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 019f563..51058e1 100644 --- a/src/main/java/tschipp/carryon/common/config/Configs.java +++ b/src/main/java/tschipp/carryon/common/config/Configs.java @@ -62,8 +62,18 @@ 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 = 10; + + @Comment("Whether entities' size matters when stacking or not") + public boolean entitySizeMattersStacking = true; } public static class WhiteList @@ -98,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:*", @@ -107,6 +119,7 @@ public class Configs { "tconstruct:*", "rustic:*", "botania:*", + "astralsorcery:*", "quark:colored_bed_*", "immersiveengineering:*", "embers:block_furnace", @@ -126,6 +139,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 49e76d8..e696fe2 100644 --- a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java +++ b/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java @@ -1,16 +1,24 @@ 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.passive.EntityVillager; 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 +32,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; @@ -89,9 +98,9 @@ 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)) { if (ItemEntity.storeEntityData(entity, world, stack)) @@ -119,10 +128,109 @@ 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) + { + + double sizeHeldEntity = entityHeld.height * entityHeld.width; + 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); + } + + if (distance < 6) + { + double tempX = entity.posX; + double tempY = entity.posY; + double tempZ = entity.posZ; + entityHeld.setPosition(tempX, tempY + 2.6, tempZ); + world.spawnEntity(entityHeld); + entityHeld.startRiding(topEntity, false); + entityHeld.setPositionAndUpdate(tempX, tempY, tempZ); + } + else + { + entityHeld.setPosition(entity.posX, entity.posY, entity.posZ); + 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)); + 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); + return; + } + } + else + { + world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_BASS, SoundCategory.PLAYERS, 0.5F, 1.5F); + return; + } + } + + } + + } } } + 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 2a455b7..91f8894 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; @@ -268,7 +270,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); @@ -276,6 +278,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()) @@ -294,6 +297,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)