Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

PutoPug

Members
  • Posts

    61
  • Joined

  • Last visited

Everything posted by PutoPug

  1. Hello, I am wondering is there any event that triggers on item durability loss? If not, any other way to run code when item durability is lost?
  2. Hello i was wondering if theres any good documented way to add a boat
  3. Hello i would like to know how to make a custom sign for my wood but vanilla code dosent work
  4. How do i increase a player's mining speed using an attribute modifier?
  5. Hello i am wondering how to change entity speed for all entities in the world
  6. @SubscribeEvent public void cancelPlayerRender(RenderPlayerEvent.Pre event){ event.setCanceled(true); } i guess this can cancel the model render, now how do i render a custom model
  7. Actually I Want to make the playermodel into a custom model
  8. I want to change the playermodel to a bat model
  9. Ok, So where do i register it?
  10. I Have A Mod which uses the vanilla leaf textures. The Leaf textures are grey like the grass_block_top.png texture. So i used "elements": [ { "from": [ 0, 0, 0 ], "to": [ 16, 16, 16 ], "faces": { "down": { "uv": [ 0, 0, 16, 16 ], "texture": "#down", "tintindex": 0, "cullface": "down" }, "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#up", "tintindex": 0, "cullface": "up" }, "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#south", "tintindex": 0, "cullface": "north" }, "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#south", "tintindex": 0, "cullface": "south" }, "west": { "uv": [ 0, 0, 16, 16 ], "texture": "#south", "tintindex": 0, "cullface": "west" }, "east": { "uv": [ 0, 0, 16, 16 ], "texture": "#south", "tintindex": 0, "cullface": "east" } } } ] in the blocks model. but the texture is still gray. i added similar code to the grass block top and it worked
  11. Here is the files package com.putopug.combat7.gui; import com.putopug.combat7.Combat7Stuff; import org.lwjgl.opengl.GL11; import net.minecraftforge.items.SlotItemHandler; import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.IContainerFactory; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.DeferredWorkQueue; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.Dist; import net.minecraft.world.World; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.math.BlockPos; import net.minecraft.util.ResourceLocation; import net.minecraft.tileentity.TileEntity; import net.minecraft.network.PacketBuffer; import net.minecraft.item.ItemStack; import net.minecraft.inventory.container.Slot; import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.Container; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.Entity; import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.client.gui.ScreenManager; import net.minecraft.client.Minecraft; import java.util.function.Supplier; import java.util.Map; import java.util.HashMap; import com.putopug.combat7.Combat7Stuff; import com.putopug.combat7.combat7; import com.mojang.blaze3d.matrix.MatrixStack; @Combat7Stuff.ModElement.Tag public class CraftoxUIGui extends Combat7Stuff.ModElement { public static HashMap guistate = new HashMap(); private static ContainerType<GuiContainerMod> containerType = null; public CraftoxUIGui(Combat7Stuff instance) { super(instance, 6); elements.addNetworkMessage(ButtonPressedMessage.class, ButtonPressedMessage::buffer, ButtonPressedMessage::new, ButtonPressedMessage::handler); elements.addNetworkMessage(GUISlotChangedMessage.class, GUISlotChangedMessage::buffer, GUISlotChangedMessage::new, GUISlotChangedMessage::handler); containerType = new ContainerType<>(new GuiContainerModFactory()); FMLJavaModLoadingContext.get().getModEventBus().register(new ContainerRegisterHandler()); } private static class ContainerRegisterHandler { @SubscribeEvent public void registerContainer(RegistryEvent.Register<ContainerType<?>> event) { event.getRegistry().register(containerType.setRegistryName("craftox_ui")); } } @OnlyIn(Dist.CLIENT) public void initElements() { DeferredWorkQueue.runLater(() -> ScreenManager.registerFactory(containerType, GuiWindow::new)); } public static class GuiContainerModFactory implements IContainerFactory { public GuiContainerMod create(int id, PlayerInventory inv, PacketBuffer extraData) { return new GuiContainerMod(id, inv, extraData); } } public static class GuiContainerMod extends Container implements Supplier<Map<Integer, Slot>> { private World world; private PlayerEntity entity; private int x, y, z; private IItemHandler internal; private Map<Integer, Slot> customSlots = new HashMap<>(); private boolean bound = false; public GuiContainerMod(int id, PlayerInventory inv, PacketBuffer extraData) { super(containerType, id); this.entity = inv.player; this.world = inv.player.world; this.internal = new ItemStackHandler(17); BlockPos pos = null; if (extraData != null) { pos = extraData.readBlockPos(); this.x = pos.getX(); this.y = pos.getY(); this.z = pos.getZ(); } if (pos != null) { if (extraData.readableBytes() == 1) { // bound to item byte hand = extraData.readByte(); ItemStack itemstack; if (hand == 0) itemstack = this.entity.getHeldItemMainhand(); else itemstack = this.entity.getHeldItemOffhand(); itemstack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).ifPresent(capability -> { this.internal = capability; this.bound = true; }); } else if (extraData.readableBytes() > 1) { extraData.readByte(); // drop padding Entity entity = world.getEntityByID(extraData.readVarInt()); if (entity != null) entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).ifPresent(capability -> { this.internal = capability; this.bound = true; }); } else { // might be bound to block TileEntity ent = inv.player != null ? inv.player.world.getTileEntity(pos) : null; if (ent != null) { ent.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).ifPresent(capability -> { this.internal = capability; this.bound = true; }); } } } this.customSlots.put(0, this.addSlot(new SlotItemHandler(internal, 0, 7, 26) { })); this.customSlots.put(1, this.addSlot(new SlotItemHandler(internal, 1, 7, 44) { })); this.customSlots.put(2, this.addSlot(new SlotItemHandler(internal, 2, 25, 26) { @Override public boolean isItemValid(ItemStack stack) { return false; } })); this.customSlots.put(3, this.addSlot(new SlotItemHandler(internal, 3, 25, 44) { })); this.customSlots.put(4, this.addSlot(new SlotItemHandler(internal, 4, 43, 26) { })); this.customSlots.put(5, this.addSlot(new SlotItemHandler(internal, 5, 43, 44) { })); this.customSlots.put(6, this.addSlot(new SlotItemHandler(internal, 6, 61, 26) { })); this.customSlots.put(7, this.addSlot(new SlotItemHandler(internal, 7, 61, 44) { })); this.customSlots.put(8, this.addSlot(new SlotItemHandler(internal, 8, 7, 62) { })); this.customSlots.put(9, this.addSlot(new SlotItemHandler(internal, 9, 25, 62) { })); this.customSlots.put(10, this.addSlot(new SlotItemHandler(internal, 10, 43, 62) { })); this.customSlots.put(11, this.addSlot(new SlotItemHandler(internal, 11, 61, 62) { })); this.customSlots.put(12, this.addSlot(new SlotItemHandler(internal, 12, 124, 44) { @Override public boolean isItemValid(ItemStack stack) { return false; } })); this.customSlots.put(13, this.addSlot(new SlotItemHandler(internal, 13, 79, 26) { })); this.customSlots.put(14, this.addSlot(new SlotItemHandler(internal, 14, 79, 62) { })); this.customSlots.put(15, this.addSlot(new SlotItemHandler(internal, 15, 79, 44) { })); this.customSlots.put(16, this.addSlot(new SlotItemHandler(internal, 16, 142, 44) { @Override public boolean isItemValid(ItemStack stack) { return false; } })); int si; int sj; for (si = 0; si < 3; ++si) for (sj = 0; sj < 9; ++sj) this.addSlot(new Slot(inv, sj + (si + 1) * 9, 0 + 8 + sj * 18, 0 + 84 + si * 18)); for (si = 0; si < 9; ++si) this.addSlot(new Slot(inv, si, 0 + 8 + si * 18, 0 + 142)); } public Map<Integer, Slot> get() { return customSlots; } @Override public boolean canInteractWith(PlayerEntity player) { return true; } @Override public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) { ItemStack itemstack = ItemStack.EMPTY; Slot slot = (Slot) this.inventorySlots.get(index); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (index < 17) { if (!this.mergeItemStack(itemstack1, 17, this.inventorySlots.size(), true)) { return ItemStack.EMPTY; } slot.onSlotChange(itemstack1, itemstack); } else if (!this.mergeItemStack(itemstack1, 0, 17, false)) { if (index < 17 + 27) { if (!this.mergeItemStack(itemstack1, 17 + 27, this.inventorySlots.size(), true)) { return ItemStack.EMPTY; } } else { if (!this.mergeItemStack(itemstack1, 17, 17 + 27, false)) { return ItemStack.EMPTY; } } return ItemStack.EMPTY; } if (itemstack1.getCount() == 0) { slot.putStack(ItemStack.EMPTY); } else { slot.onSlotChanged(); } if (itemstack1.getCount() == itemstack.getCount()) { return ItemStack.EMPTY; } slot.onTake(playerIn, itemstack1); } return itemstack; } @Override /** * Merges provided ItemStack with the first avaliable one in the * container/player inventor between minIndex (included) and maxIndex * (excluded). Args : stack, minIndex, maxIndex, negativDirection. /!\ the * Container implementation do not check if the item is valid for the slot */ protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection) { boolean flag = false; int i = startIndex; if (reverseDirection) { i = endIndex - 1; } if (stack.isStackable()) { while (!stack.isEmpty()) { if (reverseDirection) { if (i < startIndex) { break; } } else if (i >= endIndex) { break; } Slot slot = this.inventorySlots.get(i); ItemStack itemstack = slot.getStack(); if (slot.isItemValid(itemstack) && !itemstack.isEmpty() && areItemsAndTagsEqual(stack, itemstack)) { int j = itemstack.getCount() + stack.getCount(); int maxSize = Math.min(slot.getSlotStackLimit(), stack.getMaxStackSize()); if (j <= maxSize) { stack.setCount(0); itemstack.setCount(j); slot.putStack(itemstack); flag = true; } else if (itemstack.getCount() < maxSize) { stack.shrink(maxSize - itemstack.getCount()); itemstack.setCount(maxSize); slot.putStack(itemstack); flag = true; } } if (reverseDirection) { --i; } else { ++i; } } } if (!stack.isEmpty()) { if (reverseDirection) { i = endIndex - 1; } else { i = startIndex; } while (true) { if (reverseDirection) { if (i < startIndex) { break; } } else if (i >= endIndex) { break; } Slot slot1 = this.inventorySlots.get(i); ItemStack itemstack1 = slot1.getStack(); if (itemstack1.isEmpty() && slot1.isItemValid(stack)) { if (stack.getCount() > slot1.getSlotStackLimit()) { slot1.putStack(stack.split(slot1.getSlotStackLimit())); } else { slot1.putStack(stack.split(stack.getCount())); } slot1.onSlotChanged(); flag = true; break; } if (reverseDirection) { --i; } else { ++i; } } } return flag; } @Override public void onContainerClosed(PlayerEntity playerIn) { super.onContainerClosed(playerIn); if (!bound && (playerIn instanceof ServerPlayerEntity)) { if (!playerIn.isAlive() || playerIn instanceof ServerPlayerEntity && ((ServerPlayerEntity) playerIn).hasDisconnected()) { for (int j = 0; j < internal.getSlots(); ++j) { playerIn.dropItem(internal.extractItem(j, internal.getStackInSlot(j).getCount(), false), false); } } else { for (int i = 0; i < internal.getSlots(); ++i) { playerIn.inventory.placeItemBackInInventory(playerIn.world, internal.extractItem(i, internal.getStackInSlot(i).getCount(), false)); } } } } private void slotChanged(int slotid, int ctype, int meta) { if (this.world != null && this.world.isRemote()) { combat7.PACKET_HANDLER.sendToServer(new GUISlotChangedMessage(slotid, x, y, z, ctype, meta)); handleSlotAction(entity, slotid, ctype, meta, x, y, z); } } } @OnlyIn(Dist.CLIENT) public static class GuiWindow extends ContainerScreen<GuiContainerMod> { private World world; private int x, y, z; private PlayerEntity entity; public GuiWindow(GuiContainerMod container, PlayerInventory inventory, ITextComponent text) { super(container, inventory, text); this.world = container.world; this.x = container.x; this.y = container.y; this.z = container.z; this.entity = container.entity; this.xSize = 176; this.ySize = 166; } private static final ResourceLocation texture = new ResourceLocation("combat7:textures/craftox_ui.png"); @Override public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) { this.renderBackground(ms); super.render(ms, mouseX, mouseY, partialTicks); this.renderHoveredTooltip(ms, mouseX, mouseY); } @Override protected void drawGuiContainerBackgroundLayer(MatrixStack ms, float par1, int par2, int par3) { GL11.glColor4f(1, 1, 1, 1); Minecraft.getInstance().getTextureManager().bindTexture(texture); int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; this.blit(ms, k, l, 0, 0, this.xSize, this.ySize, this.xSize, this.ySize); } @Override public boolean keyPressed(int key, int b, int c) { if (key == 256) { this.minecraft.player.closeScreen(); return true; } return super.keyPressed(key, b, c); } @Override public void tick() { super.tick(); } @Override protected void drawGuiContainerForegroundLayer(MatrixStack ms, int mouseX, int mouseY) { this.font.drawString(ms, "Craftox", 6, 7, -12829636); } @Override public void onClose() { super.onClose(); Minecraft.getInstance().keyboardListener.enableRepeatEvents(false); } @Override public void init(Minecraft minecraft, int width, int height) { super.init(minecraft, width, height); minecraft.keyboardListener.enableRepeatEvents(true); } } public static class ButtonPressedMessage { int buttonID, x, y, z; public ButtonPressedMessage(PacketBuffer buffer) { this.buttonID = buffer.readInt(); this.x = buffer.readInt(); this.y = buffer.readInt(); this.z = buffer.readInt(); } public ButtonPressedMessage(int buttonID, int x, int y, int z) { this.buttonID = buttonID; this.x = x; this.y = y; this.z = z; } public static void buffer(ButtonPressedMessage message, PacketBuffer buffer) { buffer.writeInt(message.buttonID); buffer.writeInt(message.x); buffer.writeInt(message.y); buffer.writeInt(message.z); } public static void handler(ButtonPressedMessage message, Supplier<NetworkEvent.Context> contextSupplier) { NetworkEvent.Context context = contextSupplier.get(); context.enqueueWork(() -> { PlayerEntity entity = context.getSender(); int buttonID = message.buttonID; int x = message.x; int y = message.y; int z = message.z; handleButtonAction(entity, buttonID, x, y, z); }); context.setPacketHandled(true); } } public static class GUISlotChangedMessage { int slotID, x, y, z, changeType, meta; public GUISlotChangedMessage(int slotID, int x, int y, int z, int changeType, int meta) { this.slotID = slotID; this.x = x; this.y = y; this.z = z; this.changeType = changeType; this.meta = meta; } public GUISlotChangedMessage(PacketBuffer buffer) { this.slotID = buffer.readInt(); this.x = buffer.readInt(); this.y = buffer.readInt(); this.z = buffer.readInt(); this.changeType = buffer.readInt(); this.meta = buffer.readInt(); } public static void buffer(GUISlotChangedMessage message, PacketBuffer buffer) { buffer.writeInt(message.slotID); buffer.writeInt(message.x); buffer.writeInt(message.y); buffer.writeInt(message.z); buffer.writeInt(message.changeType); buffer.writeInt(message.meta); } public static void handler(GUISlotChangedMessage message, Supplier<NetworkEvent.Context> contextSupplier) { NetworkEvent.Context context = contextSupplier.get(); context.enqueueWork(() -> { PlayerEntity entity = context.getSender(); int slotID = message.slotID; int changeType = message.changeType; int meta = message.meta; int x = message.x; int y = message.y; int z = message.z; handleSlotAction(entity, slotID, changeType, meta, x, y, z); }); context.setPacketHandled(true); } } private static void handleButtonAction(PlayerEntity entity, int buttonID, int x, int y, int z) { World world = entity.world; // security measure to prevent arbitrary chunk generation if (!world.isBlockLoaded(new BlockPos(x, y, z))) return; } private static void handleSlotAction(PlayerEntity entity, int slotID, int changeType, int meta, int x, int y, int z) { World world = entity.world; // security measure to prevent arbitrary chunk generation if (!world.isBlockLoaded(new BlockPos(x, y, z))) return; } } package com.putopug.combat7; import com.putopug.combat7.combat7; import net.minecraftforge.forgespi.language.ModFileScanData; import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.ModList; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.Dist; import net.minecraft.util.ResourceLocation; import net.minecraft.tags.Tag; import net.minecraft.network.PacketBuffer; import net.minecraft.item.Item; import net.minecraft.entity.EntityType; import net.minecraft.enchantment.Enchantment; import net.minecraft.block.Block; import java.util.function.Supplier; import java.util.function.Function; import java.util.function.BiConsumer; import java.util.Set; import java.util.Map; import java.util.List; import java.util.HashMap; import java.util.Collections; import java.util.ArrayList; import com.putopug.combat7.init.items.itemGroups; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Retention; public class Combat7Stuff { public final List<ModElement> elements = new ArrayList<>(); public final List<Supplier<Block>> blocks = new ArrayList<>(); public final List<Supplier<Item>> items = new ArrayList<>(); public final List<Supplier<EntityType<?>>> entities = new ArrayList<>(); public final List<Supplier<Enchantment>> enchantments = new ArrayList<>(); public static Map<ResourceLocation, net.minecraft.util.SoundEvent> sounds = new HashMap<>(); public Combat7Stuff() { try { ModFileScanData modFileInfo = ModList.get().getModFileById("combat7").getFile().getScanResult(); Set<ModFileScanData.AnnotationData> annotations = modFileInfo.getAnnotations(); for (ModFileScanData.AnnotationData annotationData : annotations) { if (annotationData.getAnnotationType().getClassName().equals(ModElement.Tag.class.getName())) { Class<?> clazz = Class.forName(annotationData.getClassType().getClassName()); if (clazz.getSuperclass() == Combat7Stuff.ModElement.class) elements.add((Combat7Stuff.ModElement) clazz.getConstructor(this.getClass()).newInstance(this)); } } } catch (Exception e) { e.printStackTrace(); } Collections.sort(elements); elements.forEach(Combat7Stuff.ModElement::initElements); } public void registerSounds(RegistryEvent.Register<net.minecraft.util.SoundEvent> event) { for (Map.Entry<ResourceLocation, net.minecraft.util.SoundEvent> sound : sounds.entrySet()) event.getRegistry().register(sound.getValue().setRegistryName(sound.getKey())); } private int messageID = 0; public <T> void addNetworkMessage(Class<T> messageType, BiConsumer<T, PacketBuffer> encoder, Function<PacketBuffer, T> decoder, BiConsumer<T, Supplier<NetworkEvent.Context>> messageConsumer) { combat7.PACKET_HANDLER.registerMessage(messageID, messageType, encoder, decoder, messageConsumer); messageID++; } public List<ModElement> getElements() { return elements; } public List<Supplier<Block>> getBlocks() { return blocks; } public List<Supplier<Item>> getItems() { return items; } public List<Supplier<EntityType<?>>> getEntities() { return entities; } public List<Supplier<Enchantment>> getEnchantments() { return enchantments; } public static class ModElement implements Comparable<ModElement> { @Retention(RetentionPolicy.RUNTIME) public @interface Tag { } protected final Combat7Stuff elements; protected final int sortid; public ModElement(Combat7Stuff elements, int sortid) { this.elements = elements; this.sortid = sortid; } public void initElements() { } public void init(FMLCommonSetupEvent event) { } public void serverLoad(FMLServerStartingEvent event) { } @OnlyIn(Dist.CLIENT) public void clientLoad(FMLClientSetupEvent event) { } @Override public int compareTo(ModElement other) { return this.sortid - other.sortid; } } } package com.putopug.combat7; import com.putopug.combat7.init.BlockRegistryHandler; import com.putopug.combat7.init.ItemRegistryHandler; import com.putopug.combat7.init.ArmRegHandler; import com.putopug.combat7.init.ToolRegistryHandler; import com.putopug.combat7.world.biome.BiomeDummyHolder; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.network.NetworkRegistry; import net.minecraftforge.fml.network.simple.SimpleChannel; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.function.Supplier; @Mod("combat7") @Mod.EventBusSubscriber(modid = combat7.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) // //@author PutoPug // public class combat7 { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel PACKET_HANDLER = NetworkRegistry.newSimpleChannel(new ResourceLocation("combat7", "combat7"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); private static final Logger LOGGER = LogManager.getLogger(); public static final String MOD_ID = "combat7"; public static combat7 instance; public combat7() { elements = new Combat7Stuff(); FMLJavaModLoadingContext.get().getModEventBus().register(this); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); MinecraftForge.EVENT_BUS.register(new Combat7FMLBusEvents(this)); //Register mod items, blocks, biomes ItemRegistryHandler.init(); ToolRegistryHandler.init(); BlockRegistryHandler.init(); ArmRegHandler.init(); BiomeDummyHolder.init(); // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); // Register the enqueueIMC method for modloading // Register the doClientStuff method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); instance = this; } public void PrintDebugInfo() { LOGGER.warn("COMBAT LOGGER IS CURRENTLY IN ALPHA, BUGS MAY ARISE.."); LOGGER.debug("Combat7 Version:"); LOGGER.debug("Combat7 McVersion:"); LOGGER.debug("Combat7 JEI Support Version:"); LOGGER.debug("JEI MC Version:"); LOGGER.debug("Combat7 Compilation Time:"); LOGGER.debug("--GPU Info--"); LOGGER.debug("GPU Vendor:"); } private void setup(final FMLCommonSetupEvent event) { elements.getElements().forEach(element -> element.init(event)); //PrintDebugInfo(); //BiomeManager.addBiome(BiomeManager.BiomeType.WARM, new BiomeManager.BiomeEntry(RegistryKey.getOrCreateKey(Registry.BIOME_KEY, new ResourceLocation(combat7.MOD_ID, "funky_land")), 2)); } private void doClientStuff(final FMLClientSetupEvent event) { elements.getElements().forEach(element -> element.clientLoad(event)); } // You can use SubscribeEvent and let the Event Bus discover methods to call public static class RegistryEvents { @SubscribeEvent public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) { LOGGER.info("Registering Combat7"); } } public Combat7Stuff elements; @SubscribeEvent public void registerBlocks(RegistryEvent.Register<Block> event) { event.getRegistry().registerAll(elements.getBlocks().stream().map(Supplier::get).toArray(Block[]::new)); } @SubscribeEvent public void registerItems(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll(elements.getItems().stream().map(Supplier::get).toArray(Item[]::new)); } private static class Combat7FMLBusEvents { private final combat7 parent; Combat7FMLBusEvents(combat7 parent) { this.parent = parent; } @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { // do something when the server starts LOGGER.info("HELLO from server starting"); } } } package com.putopug.combat7.objects.blocks; import com.putopug.combat7.init.items.itemGroups; import net.minecraft.item.BlockItemUseContext; import net.minecraft.state.DirectionProperty; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.*; import net.minecraft.util.math.shapes.IBooleanFunction; import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; import net.minecraft.world.IWorld; import net.minecraftforge.registries.ObjectHolder; import net.minecraftforge.items.wrapper.SidedInvWrapper; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.ToolType; import net.minecraft.world.World; import net.minecraft.world.IBlockReader; import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockPos; import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.LockableLootTileEntity; import net.minecraft.network.play.server.SUpdateTileEntityPacket; import net.minecraft.network.PacketBuffer; import net.minecraft.network.NetworkManager; import net.minecraft.nbt.CompoundNBT; import net.minecraft.loot.LootContext; import net.minecraft.item.ItemStack; import net.minecraft.item.Item; import net.minecraft.item.BlockItem; import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.ItemStackHelper; import net.minecraft.inventory.InventoryHelper; import net.minecraft.inventory.ISidedInventory; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.block.material.Material; import net.minecraft.block.SoundType; import net.minecraft.block.BlockState; import net.minecraft.block.Block; import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; import java.util.stream.IntStream; import java.util.List; import java.util.Collections; import java.util.stream.Stream; import io.netty.buffer.Unpooled; import com.putopug.combat7.gui.CraftoxUIGui; import com.putopug.combat7.Combat7Stuff; @Combat7Stuff.ModElement.Tag public class CraftoxBlock extends Combat7Stuff.ModElement { @ObjectHolder("combat7:craftox") public static final Block block = null; @ObjectHolder("combat7:craftox") public static final TileEntityType<CraftoxTI> tileEntityType = null; public CraftoxBlock(Combat7Stuff instance) { super(instance, 5); FMLJavaModLoadingContext.get().getModEventBus().register(new CraftoxTIRegHandler()); } @Override public void initElements() { elements.blocks.add(() -> new BlockCus()); elements.items.add(() -> new BlockItem(block, new Item.Properties().group(itemGroups.BLOCKS)).setRegistryName(block.getRegistryName())); } private static class CraftoxTIRegHandler { @SubscribeEvent public void registerTileEntity(RegistryEvent.Register<TileEntityType<?>> event) { event.getRegistry().register(TileEntityType.Builder.create(CraftoxTI::new, block).build(null).setRegistryName("craftox")); } } public static class BlockCus extends Block { public static final DirectionProperty HOR_FACE = BlockStateProperties.HORIZONTAL_FACING; protected static final Map<Direction, VoxelShape> SHAPES = new HashMap<Direction,VoxelShape>(); public BlockCus() { super(Block.Properties.create(Material.WOOD).sound(SoundType.CHAIN).hardnessAndResistance(1.05f, 10.5f).setLightLevel(s -> 1) .harvestLevel(1).harvestTool(ToolType.AXE).slipperiness(0.7f)); setRegistryName("craftox"); this.setDefaultState(this.stateContainer.getBaseState().with(HOR_FACE, Direction.NORTH)); runCalc(Stream.of( Block.makeCuboidShape(0, 14, 0, 16, 17, 16), Block.makeCuboidShape(0, 0, 0, 16, 1, 16), Block.makeCuboidShape(13, 1, 0, 16, 14, 3), Block.makeCuboidShape(0, 1, 0, 3, 14, 3), Block.makeCuboidShape(0, 1, 13, 3, 14, 16), Block.makeCuboidShape(13, 1, 13, 16, 14, 16) ).reduce((v1, v2) -> {return VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR);}).get()); } @SuppressWarnings("deprecation") @Override public BlockState mirror(BlockState state, Mirror mirrorIn) { return state.rotate(mirrorIn.toRotation(state.get(HOR_FACE))); } @Override public BlockState rotate(BlockState state, IWorld world, BlockPos pos, Rotation direction) { return state.with(HOR_FACE, direction.rotate(state.get(HOR_FACE))); } @Nullable @Override public BlockState getStateForPlacement(BlockItemUseContext context) { return this.getDefaultState().with(HOR_FACE, context.getPlacementHorizontalFacing().getOpposite()); } @Override protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { super.fillStateContainer(builder); builder.add(HOR_FACE); } @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return SHAPES.get(state.get(HOR_FACE)); } protected static void calculateShapes(Direction to, VoxelShape shape) { VoxelShape[] buffer = new VoxelShape[] { shape, VoxelShapes.empty() }; int times = (to.getHorizontalIndex() - Direction.NORTH.getHorizontalIndex() + 4) % 4; for (int i = 0; i < times; i++) { buffer[0].forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = VoxelShapes.or(buffer[1], VoxelShapes.create(1 - maxZ, minY, minX, 1 - minZ, maxY, maxX))); buffer[0] = buffer[1]; buffer[1] = VoxelShapes.empty(); } SHAPES.put(to, buffer[0]); } protected void runCalc(VoxelShape shape) { for (Direction direction : Direction.values()) { calculateShapes(direction, shape); } } @Override public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { List<ItemStack> dropsOriginal = super.getDrops(state, builder); if (!dropsOriginal.isEmpty()) return dropsOriginal; return Collections.singletonList(new ItemStack(this, 1)); } @Override public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity entity, Hand hand, BlockRayTraceResult hit) { super.onBlockActivated(state, world, pos, entity, hand, hit); int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); if (entity instanceof ServerPlayerEntity) { NetworkHooks.openGui((ServerPlayerEntity) entity, new INamedContainerProvider() { @Override public ITextComponent getDisplayName() { return new StringTextComponent("Craftox"); } @Override public Container createMenu(int id, PlayerInventory inventory, PlayerEntity player) { return new CraftoxUIGui.GuiContainerMod(id, inventory, new PacketBuffer(Unpooled.buffer()).writeBlockPos(new BlockPos(x, y, z))); } }, new BlockPos(x, y, z)); } return ActionResultType.SUCCESS; } @Override public INamedContainerProvider getContainer(BlockState state, World worldIn, BlockPos pos) { TileEntity tileEntity = worldIn.getTileEntity(pos); return tileEntity instanceof INamedContainerProvider ? (INamedContainerProvider) tileEntity : null; } @Override public boolean hasTileEntity(BlockState state) { return true; } @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new CraftoxTI(); } @Override public boolean eventReceived(BlockState state, World world, BlockPos pos, int eventID, int eventParam) { super.eventReceived(state, world, pos, eventID, eventParam); TileEntity tileentity = world.getTileEntity(pos); return tileentity == null ? false : tileentity.receiveClientEvent(eventID, eventParam); } @Override public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) { if (state.getBlock() != newState.getBlock()) { TileEntity tileentity = world.getTileEntity(pos); if (tileentity instanceof CraftoxTI) { InventoryHelper.dropInventoryItems(world, pos, (CraftoxTI) tileentity); world.updateComparatorOutputLevel(pos, this); } super.onReplaced(state, world, pos, newState, isMoving); } } @Override public boolean hasComparatorInputOverride(BlockState state) { return true; } @Override public int getComparatorInputOverride(BlockState blockState, World world, BlockPos pos) { TileEntity tileentity = world.getTileEntity(pos); if (tileentity instanceof CraftoxTI) return Container.calcRedstoneFromInventory((CraftoxTI) tileentity); else return 0; } } public static class CraftoxTI extends LockableLootTileEntity implements ISidedInventory { private NonNullList<ItemStack> stacks = NonNullList.<ItemStack>withSize(0, ItemStack.EMPTY); protected CraftoxTI() { super(tileEntityType); } @Override public void read(BlockState blockState, CompoundNBT compound) { super.read(blockState, compound); if (!this.checkLootAndRead(compound)) { this.stacks = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY); } ItemStackHelper.loadAllItems(compound, this.stacks); } @Override public CompoundNBT write(CompoundNBT compound) { super.write(compound); if (!this.checkLootAndWrite(compound)) { ItemStackHelper.saveAllItems(compound, this.stacks); } return compound; } @Override public SUpdateTileEntityPacket getUpdatePacket() { return new SUpdateTileEntityPacket(this.pos, 0, this.getUpdateTag()); } @Override public CompoundNBT getUpdateTag() { return this.write(new CompoundNBT()); } @Override public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) { this.read(this.getBlockState(), pkt.getNbtCompound()); } @Override public int getSizeInventory() { return stacks.size(); } @Override public boolean isEmpty() { for (ItemStack itemstack : this.stacks) if (!itemstack.isEmpty()) return false; return true; } @Override public ITextComponent getDefaultName() { return new StringTextComponent("craftox"); } @Override public int getInventoryStackLimit() { return 64; } @Override public Container createMenu(int id, PlayerInventory player) { return new CraftoxUIGui.GuiContainerMod(id, player, new PacketBuffer(Unpooled.buffer()).writeBlockPos(this.getPos())); } @Override public ITextComponent getDisplayName() { return new StringTextComponent("Craftox"); } @Override protected NonNullList<ItemStack> getItems() { return this.stacks; } @Override protected void setItems(NonNullList<ItemStack> stacks) { this.stacks = stacks; } @Override public boolean isItemValidForSlot(int index, ItemStack stack) { return true; } @Override public int[] getSlotsForFace(Direction side) { return IntStream.range(0, this.getSizeInventory()).toArray(); } @Override public boolean canInsertItem(int index, ItemStack stack, @Nullable Direction direction) { return this.isItemValidForSlot(index, stack); } @Override public boolean canExtractItem(int index, ItemStack stack, Direction direction) { return true; } private final LazyOptional<? extends IItemHandler>[] handlers = SidedInvWrapper.create(this, Direction.values()); @Override public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing) { if (!this.removed && facing != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return handlers[facing.ordinal()].cast(); return super.getCapability(capability, facing); } @Override public void remove() { super.remove(); for (LazyOptional<? extends IItemHandler> handler : handlers) handler.invalidate(); } } }
  12. Lol i forgot ghub credentials, the repo is a few months outdated
×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.