Fixed entities
This commit is contained in:
parent
43f4c6c2a7
commit
ae14dd18e7
5 changed files with 33 additions and 67 deletions
12
src/main/java/biomesoplenty/client/render/RenderMudball.java
Normal file
12
src/main/java/biomesoplenty/client/render/RenderMudball.java
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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.client.render;
|
||||||
|
|
||||||
|
public class RenderMudball
|
||||||
|
{
|
||||||
|
}
|
|
@ -9,9 +9,14 @@
|
||||||
package biomesoplenty.core;
|
package biomesoplenty.core;
|
||||||
|
|
||||||
import biomesoplenty.common.command.BOPCommand;
|
import biomesoplenty.common.command.BOPCommand;
|
||||||
|
import biomesoplenty.common.entity.projectile.EntityMudball;
|
||||||
import biomesoplenty.init.*;
|
import biomesoplenty.init.*;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.entity.RenderSprite;
|
||||||
|
import net.minecraft.init.Items;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.fml.DistExecutor;
|
import net.minecraftforge.fml.DistExecutor;
|
||||||
|
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
|
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
|
||||||
|
@ -47,7 +52,7 @@ public class BiomesOPlenty
|
||||||
|
|
||||||
private void clientSetup(final FMLClientSetupEvent event)
|
private void clientSetup(final FMLClientSetupEvent event)
|
||||||
{
|
{
|
||||||
proxy.registerRenderers();
|
ModEntities.registerRendering();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadComplete(final FMLLoadCompleteEvent event) // PostRegistrationEven
|
private void loadComplete(final FMLLoadCompleteEvent event) // PostRegistrationEven
|
||||||
|
|
|
@ -18,6 +18,7 @@ import net.minecraft.client.renderer.color.BlockColors;
|
||||||
import net.minecraft.client.renderer.color.ItemColors;
|
import net.minecraft.client.renderer.color.ItemColors;
|
||||||
import net.minecraft.client.renderer.entity.RenderSprite;
|
import net.minecraft.client.renderer.entity.RenderSprite;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.init.Items;
|
||||||
import net.minecraft.init.Particles;
|
import net.minecraft.init.Particles;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemBlock;
|
import net.minecraft.item.ItemBlock;
|
||||||
|
@ -37,17 +38,6 @@ public class ClientProxy extends CommonProxy
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerRenderers()
|
|
||||||
{
|
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityMudball.class, manager ->
|
|
||||||
{
|
|
||||||
BiomesOPlenty.logger.info("Creating sprite renderer");
|
|
||||||
BiomesOPlenty.logger.info(Minecraft.getInstance().getItemRenderer() == null);
|
|
||||||
return new RenderSprite<Entity>(manager, BOPItems.mudball, Minecraft.getInstance().getItemRenderer());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init()
|
public void init()
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,7 +17,6 @@ public class CommonProxy
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerRenderers() {}
|
|
||||||
public void init() {}
|
public void init() {}
|
||||||
|
|
||||||
public void spawnParticle(BOPParticleTypes type, World parWorld, double x, double y, double z, Object... info) {}
|
public void spawnParticle(BOPParticleTypes type, World parWorld, double x, double y, double z, Object... info) {}
|
||||||
|
|
|
@ -11,84 +11,44 @@ import static biomesoplenty.api.entity.BOPEntities.*;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import biomesoplenty.api.item.BOPItems;
|
||||||
|
import biomesoplenty.core.BiomesOPlenty;
|
||||||
import com.mojang.datafixers.DataFixUtils;
|
import com.mojang.datafixers.DataFixUtils;
|
||||||
import com.mojang.datafixers.types.Type;
|
import com.mojang.datafixers.types.Type;
|
||||||
|
|
||||||
import biomesoplenty.common.entity.item.EntityBoatBOP;
|
import biomesoplenty.common.entity.item.EntityBoatBOP;
|
||||||
import biomesoplenty.common.entity.projectile.EntityMudball;
|
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.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
|
import net.minecraft.init.Items;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.datafix.DataFixesManager;
|
import net.minecraft.util.datafix.DataFixesManager;
|
||||||
import net.minecraft.util.datafix.TypeReferences;
|
import net.minecraft.util.datafix.TypeReferences;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
|
||||||
public class ModEntities
|
public class ModEntities
|
||||||
{
|
{
|
||||||
public static void init()
|
public static void init()
|
||||||
{
|
{
|
||||||
mudball = registerEntity(FixedEntityTypeBuilder.create(EntityMudball.class, EntityMudball::new), "mudball");
|
mudball = createEntity(EntityMudball.class, EntityMudball::new, "mudball", 64, 10, true);
|
||||||
boat_bop = registerEntity(FixedEntityTypeBuilder.create(EntityBoatBOP.class, EntityBoatBOP::new), "boat_bop");
|
boat_bop = createEntity(EntityBoatBOP.class, EntityBoatBOP::new, "boat_bop", 80, 3, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends Entity> EntityType<T> registerEntity(FixedEntityTypeBuilder<T> typeBuilder, String name)
|
public static <T extends Entity> EntityType<T> createEntity(Class<T> entityClass, Function<? super World, T> entityInstance, String name, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates)
|
||||||
{
|
{
|
||||||
EntityType<T> type = typeBuilder.build("biomesoplenty:" + name);
|
ResourceLocation location = new ResourceLocation("biomesoplenty", name);
|
||||||
|
EntityType<T> type = EntityType.Builder.<T>create(entityClass, entityInstance).tracker(trackingRange, updateFrequency, sendsVelocityUpdates).build(location.toString());
|
||||||
type.setRegistryName(name);
|
type.setRegistryName(name);
|
||||||
ForgeRegistries.ENTITIES.register(type);
|
ForgeRegistries.ENTITIES.register(type);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove this once Forge has fixed the bugs with calling build in
|
public static void registerRendering()
|
||||||
// EntityType.Builder, causing an exception when registering entities
|
|
||||||
public static class FixedEntityTypeBuilder<T extends Entity>
|
|
||||||
{
|
{
|
||||||
private final Class<? extends T> entityClass;
|
RenderingRegistry.registerEntityRenderingHandler(EntityMudball.class, manager -> new RenderSprite<>(manager, BOPItems.mudball, Minecraft.getInstance().getItemRenderer()));
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue