• Recently Browsing

    No registered users viewing this page.

  • Posts

    • all of it? as in my registries, my main file and is there anything else you need to see?
    • You have the player's position. This is a vector (x, y, z). You then have the look vector, which tells you where the player is looking. Simply multiply that second vector with how far you want to teleport the player (scaling it) and then add the two - you now have the target position. Although likely you want to do some additional checks, so make sure you don't teleport the player into a wall or 10m above ground.   It's a class. Look at it in your IDE.
    • When i wrote the above post it was too late and i just made a working version. So I am going to upload a cleaner version and I hope it helps someone.   I don't know when I put it out of the try scope, but it should definitely be inside.   I think it is not a public property. Maybe I am wrong, but in 1.16.5-36.0.42 it is coded as private.   Below I upload a cleaner version: public class BlockShop extends Block { public BlockShop() { super(AbstractBlock.Properties .create(Material.BARRIER) .hardnessAndResistance(-1) ); } @Override public ActionResultType onBlockActivated( BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) { if (!world.isRemote) { // Just server side needed TileEntity te = world.getTileEntity(pos.down()); if (te instanceof SignTileEntity) { SignTileEntity signTe = (SignTileEntity)te; try { String[] signText = getSignText(signTe); String sellId = signText[1]; int price = Integer.parseInt(signText[2]); int quantity = Integer.parseInt(signText[3]); buyItem(player, world, sellId, price, quantity); } catch (NumberFormatException | NullPointerException e) { e.printStackTrace(System.err); } } } return ActionResultType.CONSUME; } private String[] getSignText(SignTileEntity signTe) { CompoundNBT nbt = signTe.getUpdateTag(); String[] text = new String[4]; for (int i = 0; i < 4; i++) text[i] = ITextComponent.Serializer .getComponentFromJson(nbt.getString("Text" + (i + 1))) .getString(); return text; } private void buyItem(PlayerEntity player, World world, String itemId, int price, int quantity) { PlayerInventory inv = player.inventory; ItemStack creditStack = InitItems.CREDIT_ITEM.get().getDefaultInstance(); ItemStack itemStack = getItemStackByName(itemId); int initialCoins = inv.count(creditStack.getItem()); if (!itemStack.isEmpty() && initialCoins >= price && isAvailableSpaceForItem(quantity, player, itemStack) ) { doPayment(price, player, creditStack); giveItemsToPlayer(quantity, player, itemStack); } } private void giveItemsToPlayer(int quantity, PlayerEntity player, ItemStack itemStack) { itemStack.setCount(quantity); player.addItemStackToInventory(itemStack); } private boolean isAvailableSpaceForItem(int quantity, PlayerEntity player, ItemStack itemStack) { PlayerInventory inv = player.inventory; int leftInInventory = inv.count(itemStack.getItem()) % itemStack.getMaxStackSize(); int freeSlotsNeeded = (int)Math.ceil((quantity - leftInInventory) / (double)itemStack.getMaxStackSize()); if (freeSlotsNeeded == 0) return true; for (ItemStack is : inv.mainInventory) if (is.isEmpty() && --freeSlotsNeeded == 0) return true; return false; } private void doPayment(int price, PlayerEntity player, ItemStack coinType) { PlayerInventory inv = player.inventory; int toPay = price; while (toPay > 0) { int coinSlotIndex = inv.findSlotMatchingUnusedItem(coinType); ItemStack coinSlot = inv.getStackInSlot(coinSlotIndex); int amount = Math.min(coinSlot.getCount(), toPay); coinSlot.setCount(coinSlot.getCount() - amount); player.replaceItemInInventory(coinSlotIndex, coinSlot); toPay -= amount; } } private ItemStack getItemStackByName(String name) { ItemStack itemStack = ItemStack.EMPTY; if (name.contains("blueberry")) itemStack = InitItems.FRESISUIS_BLUEBERRY.get().getDefaultInstance(); else if (name.contains("lemon")) itemStack = InitItems.FRESISUIS_LEMON.get().getDefaultInstance(); else if (name.contains("lime")) itemStack = InitItems.FRESISUIS_LIME.get().getDefaultInstance(); else if (name.contains("orange")) itemStack = InitItems.FRESISUIS_ORANGE.get().getDefaultInstance(); else if (name.contains("strawberry")) itemStack = InitItems.FRESISUIS_STRAWBERRY.get().getDefaultInstance(); else if (name.contains("suppository")) itemStack = InitItems.GLOWING_SUPPOSITORY.get().getDefaultInstance(); return itemStack; } }   Thank you for your help  
    • I think that came from him copying the testmod file. But yes, don't conditionally register stuff.
  • Topics

  • Who's Online (See full list)