use of cavern.util.ItemMeta in project Cavern2 by kegare.
the class CavebornEventHooks method onPlayerLoggedIn.
@SubscribeEvent
public void onPlayerLoggedIn(PlayerLoggedInEvent event) {
if (!(event.player instanceof EntityPlayerMP)) {
return;
}
EntityPlayerMP player = (EntityPlayerMP) event.player;
if (!FIRST_PLAYERS.contains(player.getCachedUniqueIdString())) {
return;
}
WorldServer world = player.getServerWorld();
ConfigCaveborn.Type caveborn = GeneralConfig.caveborn.getType();
BlockPortalCavern portal = caveborn.getPortalBlock();
BlockPos pos = player.getPosition();
IPortalCache cache = PortalCache.get(player);
PatternHelper pattern = portal.createPatternHelper(world, pos);
double d0 = pattern.getForwards().getAxis() == EnumFacing.Axis.X ? (double) pattern.getFrontTopLeft().getZ() : (double) pattern.getFrontTopLeft().getX();
double d1 = pattern.getForwards().getAxis() == EnumFacing.Axis.X ? player.posZ : player.posX;
d1 = Math.abs(MathHelper.pct(d1 - (pattern.getForwards().rotateY().getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ? 1 : 0), d0, d0 - pattern.getWidth()));
double d2 = MathHelper.pct(player.posY - 1.0D, pattern.getFrontTopLeft().getY(), pattern.getFrontTopLeft().getY() - pattern.getHeight());
cache.setLastPortalVec(new Vec3d(d1, d2, 0.0D));
cache.setTeleportDirection(pattern.getForwards());
player.timeUntilPortal = player.getPortalCooldown();
portal.getTeleporter(world).placeInPortal(player, player.rotationYaw);
FIRST_PLAYERS.remove(event.player.getCachedUniqueIdString());
DimensionType type = portal.getDimension();
if (type == CaveDimensions.CAVERN) {
PlayerHelper.grantCriterion(player, "root", "entered_cavern");
} else {
String name = type.getName();
PlayerHelper.grantCriterion(player, "enter_the_" + name, "entered_" + name);
}
pos = player.getPosition();
for (BlockPos blockpos : BlockPos.getAllInBoxMutable(pos.add(-1, -1, -1), pos.add(1, 1, 1))) {
if (world.getBlockState(blockpos).getBlock() == portal) {
world.setBlockToAir(blockpos);
break;
}
}
double x = player.posX;
double y = player.posY + 0.25D;
double z = player.posZ;
world.playSound(null, x, y, z, SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.BLOCKS, 1.0F, 0.65F);
for (ItemMeta itemMeta : GeneralConfig.cavebornBonusItems.getItems()) {
ItemStack stack = itemMeta.getItemStack();
if (stack.isStackable()) {
stack = itemMeta.getItemStack(MathHelper.getInt(CaveEventHooks.RANDOM, 4, 16));
}
InventoryHelper.spawnItemStack(world, x, y, z, stack);
}
}
use of cavern.util.ItemMeta in project Cavern2 by kegare.
the class ConfigItems method refreshItems.
public void refreshItems() {
items.clear();
Arrays.stream(getValues()).filter(value -> !Strings.isNullOrEmpty(value)).forEach(value -> {
value = value.trim();
if (!value.contains(":")) {
value = "minecraft:" + value;
}
ItemMeta itemMeta;
if (value.indexOf(':') != value.lastIndexOf(':')) {
int i = value.lastIndexOf(':');
itemMeta = new ItemMeta(value.substring(0, i), NumberUtils.toInt(value.substring(i + 1)));
} else {
itemMeta = new ItemMeta(value, 0);
}
if (!itemMeta.isEmpty()) {
items.add(itemMeta);
}
});
}
use of cavern.util.ItemMeta in project Cavern2 by kegare.
the class GuiSelectItem method drawScreen.
@Override
public void drawScreen(int mouseX, int mouseY, float ticks) {
itemList.drawScreen(mouseX, mouseY, ticks);
boolean single = nameField != null || metaField != null;
String name = null;
if (single) {
name = I18n.format(Config.LANG_KEY + "select.item");
} else {
name = I18n.format(Config.LANG_KEY + "select.item.multiple");
}
if (!Strings.isNullOrEmpty(name)) {
drawCenteredString(fontRenderer, name, width / 2, 15, 0xFFFFFF);
}
super.drawScreen(mouseX, mouseY, ticks);
filterTextField.drawTextBox();
if (detailHoverChecker.checkHover(mouseX, mouseY)) {
drawHoveringText(fontRenderer.listFormattedStringToWidth(I18n.format(Config.LANG_KEY + "detail.hover"), 300), mouseX, mouseY);
} else if (instantHoverChecker.checkHover(mouseX, mouseY)) {
drawHoveringText(fontRenderer.listFormattedStringToWidth(I18n.format(Config.LANG_KEY + "instant.hover"), 300), mouseX, mouseY);
}
if (!single && !itemList.selected.isEmpty()) {
if (mouseX <= 100 && mouseY <= 20) {
drawString(fontRenderer, I18n.format(Config.LANG_KEY + "select.item.selected", itemList.selected.size()), 5, 5, 0xEFEFEF);
}
if (selectedHoverChecker.checkHover(mouseX, mouseY)) {
List<String> texts = Lists.newArrayList();
for (ItemMeta itemMeta : itemList.selected) {
name = itemList.getItemMetaTypeName(itemMeta);
if (!Strings.isNullOrEmpty(name)) {
texts.add(name);
}
}
drawHoveringText(texts, mouseX, mouseY);
}
}
}
Aggregations