parent
5bd299a9d1
commit
77e0816646
|
|
@ -34,7 +34,7 @@ public class CarryOn {
|
||||||
public static CarryOn instance;
|
public static CarryOn instance;
|
||||||
|
|
||||||
public static final String MODID = "carryon";
|
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 NAME = "Carry On";
|
||||||
public static final String ACCEPTED_VERSIONS = "[1.11,1.12)";
|
public static final String ACCEPTED_VERSIONS = "[1.11,1.12)";
|
||||||
public static final String UPDATE_JSON = "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/";
|
public static final String UPDATE_JSON = "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/";
|
||||||
|
|
|
||||||
|
|
@ -62,14 +62,15 @@ public class Configs {
|
||||||
public boolean dropCarriedWhenHit=false;
|
public boolean dropCarriedWhenHit=false;
|
||||||
|
|
||||||
@Config.RequiresMcRestart()
|
@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;
|
public boolean useScripts=false;
|
||||||
|
|
||||||
@Comment("Allows entities to be stacked using Carry On")
|
@Comment("Allows entities to be stacked using Carry On")
|
||||||
public boolean stackableEntities = true;
|
public boolean stackableEntities = true;
|
||||||
|
|
||||||
|
@Config.RangeInt(min = 1)
|
||||||
@Comment("Maximum stack limit for entities")
|
@Comment("Maximum stack limit for entities")
|
||||||
public int maxEntityStackLimit = 20;
|
public int maxEntityStackLimit = 10;
|
||||||
|
|
||||||
@Comment("Whether entities' size matters when stacking or not")
|
@Comment("Whether entities' size matters when stacking or not")
|
||||||
public boolean entitySizeMattersStacking = true;
|
public boolean entitySizeMattersStacking = true;
|
||||||
|
|
@ -107,6 +108,8 @@ public class Configs {
|
||||||
"minecraft:jungle_door",
|
"minecraft:jungle_door",
|
||||||
"minecraft:acacia_door",
|
"minecraft:acacia_door",
|
||||||
"minecraft:dark_oak_door",
|
"minecraft:dark_oak_door",
|
||||||
|
"minecraft:waterlily",
|
||||||
|
"minecraft:cake",
|
||||||
"animania:block_trough",
|
"animania:block_trough",
|
||||||
"animania:block_invisiblock",
|
"animania:block_invisiblock",
|
||||||
"colossalchests:*",
|
"colossalchests:*",
|
||||||
|
|
@ -135,6 +138,7 @@ public class Configs {
|
||||||
"skyresources:*",
|
"skyresources:*",
|
||||||
"lootbags:*",
|
"lootbags:*",
|
||||||
"exsartagine:*",
|
"exsartagine:*",
|
||||||
|
"aquamunda:tank"
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,6 @@ import tschipp.carryon.network.client.CarrySlotPacket;
|
||||||
public class ItemEntityEvents
|
public class ItemEntityEvents
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
private final List<Entity> riddenByEntities = Lists.<Entity>newArrayList();
|
|
||||||
|
|
||||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||||
public void onBlockClick(PlayerInteractEvent.RightClickBlock event)
|
public void onBlockClick(PlayerInteractEvent.RightClickBlock event)
|
||||||
{
|
{
|
||||||
|
|
@ -101,7 +98,7 @@ public class ItemEntityEvents
|
||||||
|
|
||||||
if (entity.hurtResistantTime == 0)
|
if (entity.hurtResistantTime == 0)
|
||||||
{
|
{
|
||||||
if(entity instanceof EntityAnimal)
|
if (entity instanceof EntityAnimal)
|
||||||
((EntityAnimal) entity).clearLeashed(true, true);
|
((EntityAnimal) entity).clearLeashed(true, true);
|
||||||
|
|
||||||
if (PickupHandler.canPlayerPickUpEntity(player, entity))
|
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);
|
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;
|
double sizeHeldEntity = entityHeld.height * entityHeld.width;
|
||||||
//if no riders
|
double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ);
|
||||||
if (!entity.isBeingRidden()) {
|
Entity lowestEntity = entity.getLowestRidingEntity();
|
||||||
//if entity size matters in stacking
|
int numPassengers = getAllPassengers(lowestEntity);
|
||||||
if ((CarryOnConfig.settings.entitySizeMattersStacking && sizeHeldEntity <= sizeEntity) || !CarryOnConfig.settings.entitySizeMattersStacking) {
|
if (numPassengers < CarryOnConfig.settings.maxEntityStackLimit - 1)
|
||||||
//Tame Horse so it doens't buck rider
|
{
|
||||||
if (entity instanceof EntityHorse) {
|
Entity topEntity = getTopPassenger(lowestEntity);
|
||||||
EntityHorse horse = (EntityHorse) entity;
|
|
||||||
|
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);
|
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 tempX = entity.posX;
|
||||||
double tempY = entity.posY;
|
double tempY = entity.posY;
|
||||||
double tempZ = entity.posZ;
|
double tempZ = entity.posZ;
|
||||||
entity.setPosition(tempX, tempY + 2.6, tempZ);
|
entityHeld.setPosition(tempX, tempY + 2.6, tempZ);
|
||||||
world.spawnEntity(entityHeld);
|
world.spawnEntity(entityHeld);
|
||||||
entityHeld.startRiding(entity, false);
|
entityHeld.startRiding(topEntity, false);
|
||||||
entityHeld.setPositionAndUpdate(tempX, tempY, tempZ);
|
entityHeld.setPositionAndUpdate(tempX, tempY, tempZ);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entityHeld.setPosition(entity.posX, entity.posY, entity.posZ);
|
||||||
world.spawnEntity(entityHeld);
|
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.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_BASS, SoundCategory.PLAYERS, 0.5F, 1.5F);
|
||||||
world.spawnEntity(entityHeld);
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
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);
|
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<Entity> 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<Entity> pass = entity.getPassengers();
|
||||||
|
if (!pass.isEmpty())
|
||||||
|
{
|
||||||
|
entity = pass.get(0);
|
||||||
|
top = entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return top;
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onLivingUpdate(LivingUpdateEvent event)
|
public void onLivingUpdate(LivingUpdateEvent event)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
|
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
|
||||||
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
|
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.CarryOn;
|
||||||
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
||||||
import tschipp.carryon.common.config.CarryOnConfig;
|
import tschipp.carryon.common.config.CarryOnConfig;
|
||||||
|
|
@ -261,7 +263,7 @@ public class ItemEvents
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CarryOn.network.sendToAllAround(new CarrySlotPacket(player.inventory.currentItem, player.getEntityId(), overrideHash), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256));
|
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);
|
world.setBlockToAir(pos);
|
||||||
player.setHeldItem(EnumHand.MAIN_HAND, stack);
|
player.setHeldItem(EnumHand.MAIN_HAND, stack);
|
||||||
event.setUseBlock(Result.DENY);
|
event.setUseBlock(Result.DENY);
|
||||||
|
|
@ -269,6 +271,7 @@ public class ItemEvents
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
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));
|
CarryOn.network.sendToAllAround(new CarrySlotPacket(9, player.getEntityId()), new TargetPoint(world.provider.getDimension(), player.posX, player.posY, player.posZ, 256));
|
||||||
world.setBlockState(pos, statee);
|
world.setBlockState(pos, statee);
|
||||||
if (!tag.hasNoTags())
|
if (!tag.hasNoTags())
|
||||||
|
|
@ -288,6 +291,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
|
@SubscribeEvent
|
||||||
public void onRespawn(PlayerEvent.Clone event)
|
public void onRespawn(PlayerEvent.Clone event)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user