Jump to content

The_Biggest_Noob

Members
  • Posts

    8
  • Joined

  • Last visited

Everything posted by The_Biggest_Noob

  1. Thanks, this is a way simpler method for making sittable blocks. How would I handle killing the entity when the block is broken so you can't sit in air?
  2. I have a Wrench Item and when you shift-right click a block with it, it checks if it is a stair, then replaces it with a sittable stair. I haven't actually implemented the sitting functionality yet because I have read on the forums that to make a sittable block you create an entity and when the sittable stair is clicked make the player mount the entity, but I also would like to implement a dynamic texture (not sure if that is the right term) using tile entities so when the stair changes into a sittable stair its texture doesn't change. I am not sure if this is the most practical way to do this, and I would like to know if it would affect performance having a tile entity and entity for each sittable stair. Also would I be able to have just a tile entity or entity to accomplish this? Also I'm kind-of new to modding and my code isn't very good. Wrench class: public class WrenchItem extends Item { public WrenchItem(Properties properties) { super(properties); } @Override public ActionResultType onItemUse(ItemUseContext context) { // Useful variables World world = context.getWorld(); BlockPos blockpos = context.getPos(); BlockState blockstate = world.getBlockState(blockpos); PlayerEntity player = context.getPlayer(); boolean flag = false; // On use if (player.isSneaking()) { // Shift right click // Tile entity for dynamic tex // Entity for sitting // Add custom use sound if (StairsBlock.isBlockStairs(blockstate) && !world.isRemote) { world.setBlockState(blockpos, BlockInit.SITTABLE_STAIRS.get().getDefaultState() .with(SittableStairsBlock.FACING, blockstate.get((StairsBlock.FACING))) .with(SittableStairsBlock.HALF, blockstate.get((StairsBlock.HALF))) .with(SittableStairsBlock.WATERLOGGED, blockstate.get((StairsBlock.WATERLOGGED))) .with(SittableStairsBlock.SHAPE, blockstate.get((StairsBlock.SHAPE))) , 1); flag = true; } } else { // Right click if (blockstate.getBlock() == Blocks.GRASS_BLOCK && !world.isRemote) { world.setBlockState(blockpos, Blocks.DIRT.getDefaultState(), 1); flag = true; } } // Damages wrench when used, updates changed blocks, and plays use sound if (flag) { context.getItem().damageItem(1, player, (Consumer) -> {player.sendBreakAnimation(context.getHand());}); this.playUseSound(world, blockpos); world.notifyNeighborsOfStateChange(blockpos, blockstate.getBlock()); return ActionResultType.SUCCESS; } else { return ActionResultType.PASS; } } private void playUseSound(World worldIn, BlockPos pos) { worldIn.playSound((PlayerEntity)null, pos, SoundEvents.ITEM_FIRECHARGE_USE, SoundCategory.BLOCKS, 1.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F); } }
  3. Thank you, that worked!
  4. I've been trying to register an entity and the game keeps crashing. I looked through the console log and the error says that my entity doesn't have any attributes, but I think I've registered them. Please help. Btw I am making a passive mob similar to a chicken. Mod class: package mod.destructor_ben.wmim; import mod.destructor_ben.wmim.entities.DuckEntity; import mod.destructor_ben.wmim.init.ModBlocks; import mod.destructor_ben.wmim.init.ModEntities; import mod.destructor_ben.wmim.init.ModItems; import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.DeferredWorkQueue; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @SuppressWarnings("deprecation") @Mod(WMIM.MODID) @Mod.EventBusSubscriber(modid = WMIM.MODID, bus = Bus.MOD) public class WMIM { public static final String MODID = "wmim"; public static final Logger LOGGER = LogManager.getLogger(); public WMIM() { final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); ModItems.ITEMS.register(modEventBus); LOGGER.info("Items registered"); ModBlocks.BLOCKS.register(modEventBus); LOGGER.info("Blocks registered"); ModEntities.ENTITIES.register(modEventBus); LOGGER.info("Entities registered"); } private void setup(final FMLCommonSetupEvent event) { DeferredWorkQueue.runLater(() -> { GlobalEntityTypeAttributes.put(ModEntities.DUCK.get(), DuckEntity.setCustomAttributes().create()); }); } } Entity class: package mod.destructor_ben.wmim.entities; import net.minecraft.block.BlockState; import net.minecraft.entity.AgeableEntity; import net.minecraft.entity.EntitySize; import net.minecraft.entity.EntityType; import net.minecraft.entity.MobEntity; import net.minecraft.entity.Pose; import net.minecraft.entity.ai.attributes.AttributeModifierMap; import net.minecraft.entity.ai.attributes.Attributes; import net.minecraft.entity.ai.goal.BreedGoal; import net.minecraft.entity.ai.goal.FollowParentGoal; import net.minecraft.entity.ai.goal.LookAtGoal; import net.minecraft.entity.ai.goal.LookRandomlyGoal; import net.minecraft.entity.ai.goal.PanicGoal; import net.minecraft.entity.ai.goal.SwimGoal; import net.minecraft.entity.ai.goal.TemptGoal; import net.minecraft.entity.ai.goal.WaterAvoidingRandomWalkingGoal; import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.item.crafting.Ingredient; import net.minecraft.nbt.CompoundNBT; import net.minecraft.pathfinding.PathNodeType; import net.minecraft.util.DamageSource; import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvents; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; public class DuckEntity extends AnimalEntity { private static final Ingredient TEMPTATION_ITEMS = Ingredient.fromItems(Items.WHEAT_SEEDS, Items.MELON_SEEDS, Items.PUMPKIN_SEEDS, Items.BEETROOT_SEEDS, Items.SALMON, Items.BREAD); public float wingRotation; public float destPos; public float oFlapSpeed; public float oFlap; public float wingRotDelta = 1.0F; public int timeUntilNextEgg = this.rand.nextInt(6000) + 6000; public DuckEntity(EntityType<? extends AnimalEntity> type, World worldIn) { super(type, worldIn); this.setPathPriority(PathNodeType.WATER, 5.0F); this.setPathPriority(PathNodeType.WATER_BORDER, 4.0F); } protected void registerGoals() { this.goalSelector.addGoal(0, new SwimGoal(this)); this.goalSelector.addGoal(1, new PanicGoal(this, 1.4D)); this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D)); this.goalSelector.addGoal(3, new TemptGoal(this, 1.0D, false, TEMPTATION_ITEMS)); this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.1D)); this.goalSelector.addGoal(5, new WaterAvoidingRandomWalkingGoal(this, 1.0D)); this.goalSelector.addGoal(6, new LookAtGoal(this, PlayerEntity.class, 6.0F)); this.goalSelector.addGoal(7, new LookRandomlyGoal(this)); } protected float getStandingEyeHeight(Pose poseIn, EntitySize sizeIn) { return this.isChild() ? sizeIn.height * 0.85F : sizeIn.height * 0.92F; } public static AttributeModifierMap.MutableAttribute setCustomAttributes() { return MobEntity.func_233666_p_() .createMutableAttribute(Attributes.MAX_HEALTH, 4.0D) .createMutableAttribute(Attributes.MOVEMENT_SPEED, 0.25D); } public void livingTick() { super.livingTick(); this.oFlap = this.wingRotation; this.oFlapSpeed = this.destPos; this.destPos = (float)((double)this.destPos + (double)(this.onGround ? -1 : 4) * 0.3D); this.destPos = MathHelper.clamp(this.destPos, 0.0F, 1.0F); if (!this.onGround && this.wingRotDelta < 1.0F) { this.wingRotDelta = 1.0F; } this.wingRotDelta = (float)((double)this.wingRotDelta * 0.9D); Vector3d vector3d = this.getMotion(); if (!this.onGround && vector3d.y < 0.0D) { this.setMotion(vector3d.mul(1.0D, 0.6D, 1.0D)); } this.wingRotation += this.wingRotDelta * 2.0F; //Change if (!this.world.isRemote && this.isAlive() && !this.isChild() && --this.timeUntilNextEgg <= 0) { this.playSound(SoundEvents.ENTITY_CHICKEN_EGG, 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F); this.entityDropItem(Items.EGG); this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000; } } public boolean onLivingFall(float distance, float damageMultiplier) { return false; } //change sounds protected SoundEvent getAmbientSound() { return SoundEvents.ENTITY_CHICKEN_AMBIENT; } protected SoundEvent getHurtSound(DamageSource damageSourceIn) { return SoundEvents.ENTITY_CHICKEN_HURT; } protected SoundEvent getDeathSound() { return SoundEvents.ENTITY_CHICKEN_DEATH; } protected void playStepSound(BlockPos pos, BlockState blockIn) { this.playSound(SoundEvents.ENTITY_CHICKEN_STEP, 0.15F, 1.0F); } //change this public net.minecraft.entity.passive.ChickenEntity func_241840_a(ServerWorld p_241840_1_, AgeableEntity p_241840_2_) { return EntityType.CHICKEN.create(p_241840_1_); } public boolean isBreedingItem(ItemStack stack) { return TEMPTATION_ITEMS.test(stack); } //protected int getExperiencePoints(PlayerEntity player){} public void readAdditional(CompoundNBT compound) { super.readAdditional(compound); if (compound.contains("EggLayTime")) { this.timeUntilNextEgg = compound.getInt("EggLayTime"); } } public void writeAdditional(CompoundNBT compound) { super.writeAdditional(compound); compound.putInt("EggLayTime", this.timeUntilNextEgg); } }
  5. The method I have been thinking of is using an event to check when lava is registered and using a different class to LavaFluid in the registry, one which I have made and put in my fluids package.
  6. I want to make the game so you can swim in lava and have your oxygen meter appear. Pretty much just adding water mechanics to lava
  7. I am trying to find a way to intercept registry events so i can replace the classes for lava and water. If this is possible please tell me what event should be intercepted
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.