Skip to content

Commit

Permalink
1.8.8 more support
Browse files Browse the repository at this point in the history
  • Loading branch information
boiscljo committed Sep 21, 2023
1 parent d84e070 commit 15989be
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 45 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SBA_VERSION=1.5.11-dev4-pr28
SBA_VERSION=1.5.11-dev5-pr28
PAPER_LEGACY_VERSION=1.16.5
BEDWARS_VERSION=0.2.30-SNAPSHOT
CLOUD_COMMANDS_VERSION=1.6.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,21 @@ public boolean isBreakableBlock(Block b) {
}

public boolean isBlockVisible(Block b) {
Player aiPlayer = (Player) getNPC().getEntity();
if (aiPlayer == null)
return false;
World w = aiPlayer.getWorld();
var rayTraceCheck = w.rayTraceBlocks(aiPlayer.getEyeLocation(),
aiPlayer.getEyeLocation().subtract(b.getLocation()).getDirection(),
10);
if (rayTraceCheck == null)
return false;
return rayTraceCheck.getHitBlock().equals(b);
try {
Player aiPlayer = (Player) getNPC().getEntity();
if (aiPlayer == null)
return false;
World w = aiPlayer.getWorld();
var rayTraceCheck = w.rayTraceBlocks(aiPlayer.getEyeLocation(),
aiPlayer.getEyeLocation().subtract(b.getLocation()).getDirection(),
10);
if (rayTraceCheck == null)
return false;
return rayTraceCheck.getHitBlock().equals(b);
} catch (Throwable t) {
// 1.8.8
return true;
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,48 @@ public class FakeDeathTrait extends Trait {
// 3.Getting blocks from shops
// 4.Collect ressource

class Pickup18 {
public void pick(Item itemEntity, ItemStack is, int space) {
PlayerPickupItemEvent pickupEvent = new PlayerPickupItemEvent(
(Player) npc.getEntity(),
itemEntity,
Math.max(0, is.getAmount() - space));

Bukkit.getPluginManager().callEvent(pickupEvent);

if (!pickupEvent.isCancelled()) {
Logger.trace("NPC Pickup {}", itemEntity.getItemStack());
getNpcEntity().getInventory().addItem(pickupEvent.getItem().getItemStack());
blockPlace().getBlock(getNpcEntity().getInventory());
if (pickupEvent.getRemaining() > 0) {
itemEntity.getItemStack().setAmount(pickupEvent.getRemaining());
} else {
itemEntity.remove();
}
}
}
}

class Pickup112 {
public void pick(Item itemEntity, ItemStack is, int space) {
EntityPickupItemEvent pickupEvent = new EntityPickupItemEvent(
(LivingEntity) npc.getEntity(),
itemEntity,
Math.max(0, is.getAmount() - space));
Bukkit.getPluginManager().callEvent(pickupEvent);
if (!pickupEvent.isCancelled()) {
Logger.trace("NPC Pickup {}", itemEntity.getItemStack());
getNpcEntity().getInventory().addItem(pickupEvent.getItem().getItemStack());
blockPlace().getBlock(getNpcEntity().getInventory());
if (pickupEvent.getRemaining() > 0) {
itemEntity.getItemStack().setAmount(pickupEvent.getRemaining());
} else {
itemEntity.remove();
}
}
}
}

private List<AiGoal> goals = new ArrayList<>();
@Getter
@Setter
Expand Down Expand Up @@ -157,39 +199,9 @@ && getPlayerObject().getGameMode() == GameMode.SURVIVAL) {
int space = getAmountOfSpaceFor(is, getNpcEntity().getInventory());
if (space > 0) {
if (Version.isVersion(1, 12)) {
EntityPickupItemEvent pickupEvent = new EntityPickupItemEvent(
(LivingEntity) npc.getEntity(),
itemEntity,
Math.max(0, is.getAmount() - space));
Bukkit.getPluginManager().callEvent(pickupEvent);
if (!pickupEvent.isCancelled()) {
Logger.trace("NPC Pickup {}", itemEntity.getItemStack());
getNpcEntity().getInventory().addItem(pickupEvent.getItem().getItemStack());
blockPlace().getBlock(getNpcEntity().getInventory());
if (pickupEvent.getRemaining() > 0) {
itemEntity.getItemStack().setAmount(pickupEvent.getRemaining());
} else {
itemEntity.remove();
}
}
new Pickup112().pick(itemEntity, is, space);
} else {
PlayerPickupItemEvent pickupEvent = new PlayerPickupItemEvent(
(Player) npc.getEntity(),
itemEntity,
Math.max(0, is.getAmount() - space));

Bukkit.getPluginManager().callEvent(pickupEvent);

if (!pickupEvent.isCancelled()) {
Logger.trace("NPC Pickup {}", itemEntity.getItemStack());
getNpcEntity().getInventory().addItem(pickupEvent.getItem().getItemStack());
blockPlace().getBlock(getNpcEntity().getInventory());
if (pickupEvent.getRemaining() > 0) {
itemEntity.getItemStack().setAmount(pickupEvent.getRemaining());
} else {
itemEntity.remove();
}
}
new Pickup18().pick(itemEntity, is, space);
}
}
}
Expand All @@ -202,8 +214,12 @@ public static int getAmountOfSpaceFor(ItemStack m, Inventory inv) {
m.setAmount(1);
var oneStack = new ItemStack(m).getMaxStackSize();
int space = 0;

var inventoryContent = inv.getStorageContents();
ItemStack[] inventoryContent = null;
try {
inventoryContent = inv.getStorageContents();
} catch (Throwable t) {
inventoryContent = inv.getContents();
}

for (int index = 0; index < inventoryContent.length; index++) {
var itemStack = inventoryContent[index];
Expand Down

0 comments on commit 15989be

Please sign in to comment.