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

CommandCore

Members
  • Posts

    36
  • Joined

  • Last visited

CommandCore's Achievements

Tree Puncher

Tree Puncher (2/8)

1

Reputation

  1. Hey all, I was wondering how I would copy the contents of a TileEntity to another, such as copying a chest's contents, or a furnace's items and cook time, etc., to another chest/furnace that already exists in the world. Any help is appreciated. Cheers.
  2. Solved. Removed @OnlyIn from HeartballEntity and added this to the end of my Entity class: @Override public IPacket<?> createSpawnPacket() { return NetworkHooks.getEntitySpawningPacket(this); } Thanks for the help, Cheers.
  3. Sure: HeartballRenderer.java package com.agilapathy.twodotx.entities.heartball; import com.agilapathy.twodotx.TwoDotXMod; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Matrix3f; import net.minecraft.util.math.vector.Matrix4f; import net.minecraft.util.math.vector.Vector3f; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.client.registry.IRenderFactory; import javax.annotation.Nullable; @OnlyIn(Dist.CLIENT) public class HeartballRenderer extends EntityRenderer<HeartballEntity> { private static final ResourceLocation HEARTBALL_TEXTURE = new ResourceLocation(TwoDotXMod.MOD_ID + ":textures/entity/heartball.png"); private static final RenderType field_229044_e_ = RenderType.getEntityCutoutNoCull(HEARTBALL_TEXTURE); public HeartballRenderer(EntityRendererManager renderManagerIn) { super(renderManagerIn); } protected int getBlockLight(HeartballEntity entityIn, BlockPos partialTicks) { return 15; } public void render(HeartballEntity entityIn, float entityYaw, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn) { matrixStackIn.push(); matrixStackIn.scale(2.0F, 2.0F, 2.0F); matrixStackIn.rotate(this.renderManager.getCameraOrientation()); matrixStackIn.rotate(Vector3f.YP.rotationDegrees(180.0F)); MatrixStack.Entry matrixstack$entry = matrixStackIn.getLast(); Matrix4f matrix4f = matrixstack$entry.getMatrix(); Matrix3f matrix3f = matrixstack$entry.getNormal(); IVertexBuilder ivertexbuilder = bufferIn.getBuffer(field_229044_e_); func_229045_a_(ivertexbuilder, matrix4f, matrix3f, packedLightIn, 0.0F, 0, 0, 1); func_229045_a_(ivertexbuilder, matrix4f, matrix3f, packedLightIn, 1.0F, 0, 1, 1); func_229045_a_(ivertexbuilder, matrix4f, matrix3f, packedLightIn, 1.0F, 1, 1, 0); func_229045_a_(ivertexbuilder, matrix4f, matrix3f, packedLightIn, 0.0F, 1, 0, 0); matrixStackIn.pop(); super.render(entityIn, entityYaw, partialTicks, matrixStackIn, bufferIn, packedLightIn); } private static void func_229045_a_(IVertexBuilder p_229045_0_, Matrix4f p_229045_1_, Matrix3f p_229045_2_, int p_229045_3_, float p_229045_4_, int p_229045_5_, int p_229045_6_, int p_229045_7_) { p_229045_0_.pos(p_229045_1_, p_229045_4_ - 0.5F, (float)p_229045_5_ - 0.25F, 0.0F).color(255, 255, 255, 255).tex((float)p_229045_6_, (float)p_229045_7_).overlay(OverlayTexture.NO_OVERLAY).lightmap(p_229045_3_).normal(p_229045_2_, 0.0F, 1.0F, 0.0F).endVertex(); } /** * Returns the location of an entity's texture. */ @Override public ResourceLocation getEntityTexture(HeartballEntity entity) { return HEARTBALL_TEXTURE; } } HeartballEntity.java package com.agilapathy.twodotx.entities.heartball; import java.util.List; import com.agilapathy.twodotx.util.RegistryHandler; import net.minecraft.entity.*; import net.minecraft.entity.projectile.DamagingProjectileEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.particles.IParticleData; import net.minecraft.particles.ParticleTypes; import net.minecraft.potion.EffectInstance; import net.minecraft.potion.Effects; import net.minecraft.util.DamageSource; import net.minecraft.util.math.EntityRayTraceResult; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; public class HeartballEntity extends DamagingProjectileEntity{ public HeartballEntity(EntityType<? extends HeartballEntity> p_i50171_1_, World p_i50171_2_) { super(p_i50171_1_, p_i50171_2_); } @OnlyIn(Dist.CLIENT) public HeartballEntity(World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ) { super(RegistryHandler.HEARTBALL_PROJECTILE.get(), x, y, z, accelX, accelY, accelZ, worldIn); } public HeartballEntity(World worldIn, LivingEntity shooter, double accelX, double accelY, double accelZ) { super(RegistryHandler.HEARTBALL_PROJECTILE.get(), shooter, accelX, accelY, accelZ, worldIn); } /** * Called when this EntityFireball hits a block or entity. */ protected void onImpact(RayTraceResult result) { super.onImpact(result); Entity entity = this.func_234616_v_(); if (result.getType() != RayTraceResult.Type.ENTITY || !((EntityRayTraceResult)result).getEntity().isEntityEqual(entity)) { if (!this.world.isRemote) { List<LivingEntity> list = this.world.getEntitiesWithinAABB(LivingEntity.class, this.getBoundingBox().grow(4.0D, 2.0D, 4.0D)); AreaEffectCloudEntity areaeffectcloudentity = new AreaEffectCloudEntity(this.world, this.getPosX(), this.getPosY(), this.getPosZ()); if (entity instanceof LivingEntity) { areaeffectcloudentity.setOwner((LivingEntity)entity); } areaeffectcloudentity.setParticleData(ParticleTypes.DRAGON_BREATH); areaeffectcloudentity.setRadius(3.0F); areaeffectcloudentity.setDuration(600); areaeffectcloudentity.setRadiusPerTick((7.0F - areaeffectcloudentity.getRadius()) / (float)areaeffectcloudentity.getDuration()); areaeffectcloudentity.addEffect(new EffectInstance(Effects.INSTANT_DAMAGE, 1, 1)); if (!list.isEmpty()) { for(LivingEntity livingentity : list) { double d0 = this.getDistanceSq(livingentity); if (d0 < 16.0D) { areaeffectcloudentity.setPosition(livingentity.getPosX(), livingentity.getPosY(), livingentity.getPosZ()); break; } } } this.world.playEvent(2006, this.getPosition(), this.isSilent() ? -1 : 1); this.world.addEntity(areaeffectcloudentity); this.remove(); } } } /** * Returns true if other Entities should be prevented from moving through this Entity. */ public boolean canBeCollidedWith() { return false; } /** * Called when the entity is attacked. */ public boolean attackEntityFrom(DamageSource source, float amount) { return false; } protected IParticleData getParticle() { return ParticleTypes.DRAGON_BREATH; } protected boolean isFireballFiery() { return false; } } TwoDotXMod.java (Main class) package com.agilapathy.twodotx; import com.agilapathy.twodotx.capabilities.*; import com.agilapathy.twodotx.entities.heartball.HeartballEntity; import com.agilapathy.twodotx.entities.heartball.HeartballRenderer; import com.agilapathy.twodotx.gen.GenerationEvents; import com.agilapathy.twodotx.util.ClientEvents; import com.agilapathy.twodotx.util.RegistryHandler; import com.agilapathy.twodotx.util.functions.*; import net.minecraft.block.DispenserBlock; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ItemRenderer; import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.client.renderer.entity.SpriteRenderer; import net.minecraft.entity.EntityType; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.client.registry.IRenderFactory; import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; 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; // The value here should match an entry in the META-INF/mods.toml file @Mod("twodotx") public class TwoDotXMod { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel PACKET_HANDLER = NetworkRegistry.newSimpleChannel(new ResourceLocation("twodotx", "twodotx"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); // Directly reference a log4j logger. private static final Logger LOGGER = LogManager.getLogger(); public static final String MOD_ID = "twodotx"; public TwoDotXMod() { // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); //FMLJavaModLoadingContext.get().getModEventBus().addListener(GenerationMain::generate); // Register the doClientStuff method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); //Register Other Stuff RegistryHandler.init(); // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { } private void doClientStuff(final FMLClientSetupEvent event) { RenderingRegistry.registerEntityRenderingHandler(RegistryHandler.HEARTBALL_PROJECTILE.get(), HeartballRenderer::new); } } RegistryHandler.java package com.agilapathy.twodotx.util; import com.agilapathy.twodotx.TwoDotXMod; import com.agilapathy.twodotx.blocks.*; import com.agilapathy.twodotx.entities.heartball.HeartballEntity; import com.agilapathy.twodotx.items.*; import com.agilapathy.twodotx.util.enums.CustomArmorMaterial; import com.agilapathy.twodotx.util.enums.CustomItemTier; import net.minecraft.block.*; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentType; import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityType; import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.item.*; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import static net.minecraftforge.registries.DeferredRegister.create; public class RegistryHandler { public static final DeferredRegister<EntityType<?>> ENTITIES = create(ForgeRegistries.ENTITIES, TwoDotXMod.MOD_ID); public static void init() { ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus()); } //Entities public static final RegistryObject<EntityType<HeartballEntity>> HEARTBALL_PROJECTILE = ENTITIES.register("heartball", () -> EntityType.Builder.<HeartballEntity>create(HeartballEntity::new, EntityClassification.MISC).size(0.25F, 0.25F).trackingRange(4).func_233608_b_(10).build("heartball")); }
  4. I tried this with no luck: RenderingRegistry.registerEntityRenderingHandler(RegistryHandler.HEARTBALL_PROJECTILE.get(), HeartballRenderer::new);
  5. My projectile is working completely as intended, but it's invisible for some reason. I think it has something to do with how I'm registering its renderer. Here I'm using an item to spawn it, identical to how a dragon would shoot a fireball: Here's my Registry Object entry: public static final RegistryObject<EntityType<HeartballEntity>> HEARTBALL_PROJECTILE = ENTITIES.register("heartball", () -> EntityType.Builder.<HeartballEntity>create(HeartballEntity::new, EntityClassification.MISC).size(0.25F, 0.25F).trackingRange(4).func_233608_b_(10).build("heartball")); Here's the code in my main class that's handling the registry of the rendering: private void doClientStuff(final FMLClientSetupEvent event) { registerEntityModels(event.getMinecraftSupplier()); } private void registerEntityModels(Supplier<Minecraft> minecraft) { EntityRendererManager renderer = minecraft.get().getRenderManager(); renderer.register(RegistryHandler.HEARTBALL_PROJECTILE.get(), new HeartballRenderer(renderer)); } (FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); is called in the constructor.) HeartballEntity and HeartballRenderer are identical to DragonFireballEntity and DragonFireballRenderer for example purposes, with the exception of the texture in HeartballRenderer, which I have changed to a target texture of my own: private static final ResourceLocation HEARTBALL_TEXTURE = new ResourceLocation(TwoDotXMod.MOD_ID + ":textures/entity/heartball.png"); I appreciate any help, let me know if more information is needed. Cheers.
  6. I'm trying to find a way to change the water color of vanilla biomes. I know that you can do this for custom biomes, but how would I go about this for vanilla biomes? Example: turning desert water into a light-ish yellow. Cheers.
  7. Got it. I wasn't eager to do it at first because I thought you weren't able to specify the item used, but I found out that you can through event.getItemStack().getItem() Thanks man.
  8. Hey all, I'm trying to get something to happen when a beehive or bee nest is harvested (Getting honeycombs from it) but I've already tried overriding shears (it's called on the block before the onUtemUse of the shears, so that's never called when the honey level is 5 on a bee nest or beehive) I also tried overriding the vanilla block, but bee's seem to be able to go into the hive, just not make honey It would be nice if there was some sort of PlayerEvent.HarvestBeehive event or something, but I can't seem to find one that can match that. Any other ideas, or maybe I'm missing something? Thanks for the help guys.
  9. Okay then, I'm gonna mark this as solved because I got a working product. I guess people can open another thread for efficiency of this method. 👍
  10. Ah, I see. So unnecessary casting and assigning of variables via strings is the culprit of this bad practice? Does this contribute to inefficiency? From that site you posted, that seems to be the case.
  11. Because I wanted the ability to add custom values when setting them. For example, I wouldn't have to go into the capability and add a new variable, I can just say "Set the variable 'Working' to 'true'." And if its trying to get a variable that hasn't been set yet, it'll return 0 or "" depending on what kind of variable I set it as, (Notice the "string" argument.) Its sort of mimicking the stuff you can do with getPersistentData() on an entity. TLDR; Convenience. ¯\_(ツ)_/¯
  12. Got it. Moved it to the client event class. Everything seems to be working. It is a Forge capability, with an interface, class, provider, and storage, along with a AttachCapabilitiesEvent<Entity> called in a class to attach it to PlayerEntity's. Sorry if that wasn't clear in my last post. Unless you're talking about a capability that is already in Forge?
  13. Alright, put this in a class that's only for client events. private static final Field field = ObfuscationReflectionHelper.findField(Minecraft.class, "field_71467_ac"); @SubscribeEvent public static void onClientTickEvent(TickEvent.ClientTickEvent event) throws IllegalAccessException { if(event.phase == TickEvent.Phase.START) { try { if(CustomCapabilities.getPlayer(Minecraft.getInstance().player).getVariable("string", "HasBrokenMyBlock").equals("true")){ field.setInt(Minecraft.getInstance(), 0); CustomCapabilities.getPlayer(Minecraft.getInstance().player).setVariable("HasBrokenMyBlock", "false"); } } catch (NullPointerException e) {} } } I removed here is the new code that stayed in that class: @SubscribeEvent public void farmBlock(PlayerInteractEvent.RightClickBlock event) { if(event.getPlayer().getHeldItem(event.getHand()).getItem().equals(Items.SHEARS) && event.getWorld().getBlockState(event.getPos()).equals(RegistryHandler.MY_BLOCK.get().getDefaultState())){ CustomCapabilities.getPlayer(event.getPlayer()).setVariable("HasBrokenMyBlock", "true"); } } And is the custom capability system of mine that I was talking about. You can think of it as setting a value on a capability that is attached to PlayerEntitys. The real variable-setting stuff is buried under a bunch of static methods for convenience. This seems to be the only way to put a boolean value on my player that really just functions to link the functions of the RightClickBlock event to the ClientTickEvent. I suppose if there was a better way to link them, I wouldn't have to do this. Everything works, even when the client logged into the server.
  14. I believe this new version covers everything you said. I used an attached player capability for the boolean. private static final Field field = ObfuscationReflectionHelper.findField(Minecraft.class, "rightClickDelayTimer"); @SubscribeEvent public void onClientTickEvent(TickEvent.ClientTickEvent event) throws IllegalAccessException { if(event.phase == TickEvent.Phase.START) { try { if(CustomCapabilities.getPlayer(Minecraft.getInstance().player).getVariable("string", "HasBrokenMyBlock").equals("true")){ field.setInt(Minecraft.getInstance(), 0); CustomCapabilities.getPlayer(Minecraft.getInstance().player).setVariable("HasBrokenMyBlock", "false"); } } catch (NullPointerException e) {} } } @SubscribeEvent public void farmBlock(PlayerInteractEvent.RightClickBlock event) { if(event.getPlayer() == Minecraft.getInstance().player){ if(event.getPlayer().getHeldItem(event.getHand()).getItem().equals(Items.SHEARS) && event.getWorld().getBlockState(event.getPos()).equals(RegistryHandler.MY_BLOCK.get().getDefaultState())){ CustomCapabilities.getPlayer(event.getPlayer()).setVariable("HasBrokenMyBlock", "true"); } } } Everthing works, but a server instance isn't running because it doesn't like the ClientTickEvent: "Attempted to load class net/minecraft/client/entity/player/ClientPlayerEntity for invalid dist DEDICATED_SERVER" Tried to use regular TickEvent and it gave me the same error.
×
×
  • Create New...

Important Information

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