Attempted to get mudballs working. Seems entity registration is buggy

This commit is contained in:
Adubbz 2019-01-12 11:51:55 +11:00
parent a67b28bbd2
commit 75bf89e31f
8 changed files with 277 additions and 2 deletions

View File

@ -0,0 +1,15 @@
/*******************************************************************************
* Copyright 2014-2019, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.api.entity;
import net.minecraft.entity.EntityType;
public class BOPEntities
{
public static EntityType<?> mudball;
}

View File

@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright 2014-2019, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.common.entity.projectile;
import biomesoplenty.api.entity.BOPEntities;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
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 EntityMudball extends EntityThrowable
{
public EntityMudball(World world)
{
super(BOPEntities.mudball, world);
}
public EntityMudball(double x, double y, double z, World world)
{
super(BOPEntities.mudball, x, y, z, world);
}
public EntityMudball(World world, EntityLivingBase thrower)
{
super(BOPEntities.mudball, thrower, world);
}
@OnlyIn(Dist.CLIENT)
@Override
public void handleStatusUpdate(byte id)
{
if (id == 3)
{
for (int i = 0; i < 8; ++i)
{
//BiomesOPlenty.proxy.spawnParticle(BOPParticleTypes.MUD, this.world, this.posX, this.posY, this.posZ);
}
}
}
@Override
protected void onImpact(RayTraceResult hit)
{
if (hit.entity != null)
{
hit.entity.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0.0F);
}
if (!this.world.isRemote)
{
this.world.setEntityState(this, (byte)3);
this.remove();
}
}
}

View File

@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright 2014-2019, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.common.item;
import biomesoplenty.common.entity.projectile.EntityMudball;
import biomesoplenty.common.util.inventory.ItemGroupBOP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
public class ItemMudball extends Item
{
public ItemMudball()
{
super(new Item.Builder().group(ItemGroupBOP.instance).maxStackSize(16));
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
ItemStack stack = player.getHeldItem(hand);
if (!player.abilities.isCreativeMode)
{
stack.setCount(stack.getCount() - 1);
}
world.playSound(player, player.getPosition(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
if (!world.isRemote)
{
EntityMudball mudball = new EntityMudball(world, player);
mudball.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
world.spawnEntity(mudball);
}
player.addStat(StatList.ITEM_USED.get(this));
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
}

View File

@ -9,9 +9,11 @@
package biomesoplenty.core;
import biomesoplenty.init.ModBlocks;
import biomesoplenty.init.ModEntities;
import biomesoplenty.init.ModItems;
import biomesoplenty.init.ModSounds;
import net.minecraft.init.Bootstrap;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
@ -23,6 +25,7 @@ public class BiomesOPlenty
public static final String MOD_ID = "biomesoplenty";
public static BiomesOPlenty instance;
public static CommonProxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> CommonProxy::new);
public BiomesOPlenty()
{
@ -32,12 +35,14 @@ public class BiomesOPlenty
FMLModLoadingContext.get().getModEventBus().addListener(this::init);
ModSounds.init();
ModEntities.init();
ModBlocks.init();
ModItems.init();
}
private void preInit(final FMLPreInitializationEvent event)
{
proxy.preInit();
}
private void init(final FMLInitializationEvent event)

View File

@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright 2014-2019, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.core;
import biomesoplenty.api.item.BOPItems;
import biomesoplenty.common.entity.projectile.EntityMudball;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderSprite;
import net.minecraft.entity.Entity;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
public class ClientProxy extends CommonProxy
{
public ClientProxy()
{
}
@Override
public void preInit()
{
RenderingRegistry.registerEntityRenderingHandler(EntityMudball.class, manager -> new RenderSprite<Entity>(manager, BOPItems.mudball, Minecraft.getInstance().getItemRenderer()));
}
}

View File

@ -0,0 +1,18 @@
/*******************************************************************************
* Copyright 2014-2019, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.core;
public class CommonProxy
{
public CommonProxy()
{
}
public void preInit() {}
}

View File

@ -0,0 +1,94 @@
/*******************************************************************************
* Copyright 2014-2019, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.init;
import biomesoplenty.common.entity.projectile.EntityMudball;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.types.Type;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.item.Item;
import net.minecraft.util.SharedConstants;
import net.minecraft.util.datafix.DataFixesManager;
import net.minecraft.util.datafix.TypeReferences;
import net.minecraft.world.World;
import net.minecraftforge.registries.ForgeRegistries;
import java.util.function.Function;
import static biomesoplenty.api.entity.BOPEntities.*;
public class ModEntities
{
public static void init()
{
mudball = registerEntity(FixedEntityTypeBuilder.create(EntityMudball.class, EntityMudball::new), "mudball");
}
public static <T extends Entity> EntityType<T> registerEntity(FixedEntityTypeBuilder<T> typeBuilder, String name)
{
EntityType<T> type = typeBuilder.build("biomesoplenty:" + name);
type.setRegistryName(name);
ForgeRegistries.ENTITIES.register(type);
return type;
}
// TODO: Remove this once Forge has fixed the bugs with calling build in
// EntityType.Builder, causing an exception when registering entities
public static class FixedEntityTypeBuilder<T extends Entity>
{
private final Class<? extends T> entityClass;
private final Function<? super World, ? extends T> factory;
private boolean serializable = true;
private boolean summonable = true;
private FixedEntityTypeBuilder(Class<? extends T> entityClassIn, Function<? super World, ? extends T> factoryIn)
{
this.entityClass = entityClassIn;
this.factory = factoryIn;
}
public static <T extends Entity> FixedEntityTypeBuilder<T> create(Class<? extends T> entityClassIn, Function<? super World, ? extends T> factoryIn)
{
return new FixedEntityTypeBuilder<T>(entityClassIn, factoryIn);
}
public static <T extends Entity> FixedEntityTypeBuilder<T> createNothing(Class<? extends T> entityClassIn)
{
return new FixedEntityTypeBuilder<T>(entityClassIn, (p_200708_0_) -> {
return null;
});
}
public FixedEntityTypeBuilder<T> disableSummoning()
{
this.summonable = false;
return this;
}
public FixedEntityTypeBuilder<T> disableSerialization()
{
this.serializable = false;
return this;
}
public EntityType<T> build(String id) {
Type<?> type = null;
if (this.serializable) {
try {
type = DataFixesManager.getDataFixer().getSchema(DataFixUtils.makeKey(1519)).getChoiceType(TypeReferences.ENTITY_TYPE, id);
} catch (IllegalArgumentException e) {
// Ignore, we don't care
}
}
return new EntityType<T>(this.entityClass, this.factory, this.serializable, this.summonable, type);
}
}
}

View File

@ -11,6 +11,7 @@ import static biomesoplenty.api.item.BOPItems.*;
import biomesoplenty.api.sound.BOPSounds;
import biomesoplenty.common.item.ItemBOPRecord;
import biomesoplenty.common.item.ItemMudball;
import biomesoplenty.common.util.inventory.ItemGroupBOP;
import net.minecraft.item.Item;
import net.minecraftforge.registries.ForgeRegistries;
@ -19,8 +20,7 @@ public class ModItems
{
public static void init()
{
// TODO: This should be ItemMudball
mudball = registerItem(new Item(new Item.Builder().group(ItemGroupBOP.instance)), "mudball");
mudball = registerItem(new ItemMudball(), "mudball");
mud_brick = registerItem(new Item(new Item.Builder().group(ItemGroupBOP.instance)), "mud_brick");
pile_of_ashes = registerItem(new Item(new Item.Builder().group(ItemGroupBOP.instance)), "pile_of_ashes");
chunk_of_flesh = registerItem(new Item(new Item.Builder().group(ItemGroupBOP.instance)), "chunk_of_flesh");