use of de.budschie.bmorph.entity.MorphEntity in project BudschieMorphMod by Budschie.
the class Events method onPlayerDeathEvent.
@SubscribeEvent
public static void onPlayerDeathEvent(LivingDeathEvent event) {
if (event.getEntityLiving() instanceof PlayerEntity && !event.getEntity().world.isRemote) {
PlayerEntity player = (PlayerEntity) event.getEntityLiving();
LazyOptional<IMorphCapability> cap = player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
if (cap.isPresent()) {
IMorphCapability resolved = cap.resolve().get();
resolved.deapplyAbilities(player);
if (!ServerSetup.server.getGameRules().getBoolean(BMorphMod.KEEP_MORPH_INVENTORY)) {
for (MorphItem item : resolved.getMorphList().getMorphArrayList()) {
MorphEntity morphEntity = new MorphEntity(player.world, item);
morphEntity.setPosition(player.getPosX(), player.getPosY(), player.getPosZ());
player.world.addEntity(morphEntity);
}
}
}
}
}
use of de.budschie.bmorph.entity.MorphEntity in project BudschieMorphMod by Budschie.
the class Events method onPlayerKilledLivingEntity.
@SubscribeEvent
public static void onPlayerKilledLivingEntity(LivingDeathEvent event) {
if (!event.getEntity().world.isRemote && ServerSetup.server.getGameRules().getBoolean(BMorphMod.DO_MORPH_DROPS)) {
if (event.getSource().getTrueSource() instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) event.getSource().getTrueSource();
if (!(player instanceof FakePlayer)) {
LazyOptional<IMorphCapability> playerMorph = player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
if (playerMorph.isPresent()) {
MorphItem morphItem = MorphManagerHandlers.createMorphFromDeadEntity(event.getEntity());
if (morphItem != null) {
IMorphCapability resolved = playerMorph.resolve().get();
boolean shouldMorph = !ConfigManager.INSTANCE.get(BlacklistData.class).isInBlacklist(event.getEntity().getType().getRegistryName());
if (!resolved.getMorphList().contains(morphItem) && shouldMorph) {
MorphEntity morphEntity = new MorphEntity(event.getEntity().world, morphItem);
morphEntity.setPosition(event.getEntity().getPosX(), event.getEntity().getPosY(), event.getEntity().getPosZ());
event.getEntity().world.addEntity(morphEntity);
}
}
}
}
}
}
}
use of de.budschie.bmorph.entity.MorphEntity in project BudschieMorphMod by Budschie.
the class MorphEntityRenderer method render.
@Override
public void render(MorphEntity entity, float something, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int light) {
Entity toRender = entityCache.get(entity.getUniqueID());
if (toRender == null) {
// Check if the entity was not loaded in successfull
if (entityCache.containsKey(entity.getUniqueID())) {
return;
} else {
toRender = entity.getMorphItem().createEntity(entity.world);
// If we did not succeed, set entityCache value to null!
if (toRender == null) {
entityCache.put(entity.getUniqueID(), null);
return;
}
if (toRender instanceof LivingEntity) {
LivingEntity entityLiving = (LivingEntity) toRender;
entityLiving.deathTime = 0;
entityLiving.hurtTime = 0;
}
entityCache.put(entity.getUniqueID(), toRender);
}
}
toRender.ticksExisted = entity.ticksExisted;
EntityRenderer<? super Entity> manager = Minecraft.getInstance().getRenderManager().getRenderer(toRender);
toRender.prevPosX = entity.prevPosX;
toRender.prevPosY = entity.prevPosY;
toRender.prevPosZ = entity.prevPosZ;
toRender.setPosition(entity.getPosX(), entity.getPosY(), entity.getPosZ());
matrixStack.rotate(Vector3f.YP.rotationDegrees(((toRender.ticksExisted + partialTicks) * 5f) % 360));
matrixStack.translate(0, Math.sin((toRender.ticksExisted + partialTicks) * 0.25f) * 0.15f + 0.15f, 0);
manager.render(toRender, 0, partialTicks, matrixStack, renderType -> {
final IVertexBuilder builder;
if (renderType instanceof RenderType.Type) {
Optional<ResourceLocation> rs = ((RenderType.Type) renderType).renderState.texture.texture;
if (rs.isPresent()) {
RenderType newType = RenderType.getEntityTranslucent(rs.get());
if (!newType.getVertexFormat().equals(renderType.getVertexFormat()))
return buffer.getBuffer(renderType);
builder = buffer.getBuffer(newType);
} else {
System.out.println("If you see this, then there is an error with rendering that you should report as a bug.");
return buffer.getBuffer(renderType);
}
} else {
System.out.println("If you see this, then there is an error with rendering that you should report as a bug.");
return buffer.getBuffer(renderType);
}
// IVertexBuilder builder = (p_getBuffer_1_ instanceof RenderType.Type) ? buffer.getBuffer(RenderType.getEntityTranslucent(((RenderType.Type)p_getBuffer_1_).renderState.texture) : buffer.getBuffer(p_getBuffer_1_);
return new IVertexBuilder() {
@Override
public void addVertex(float x, float y, float z, float red, float green, float blue, float alpha, float texU, float texV, int overlayUV, int lightmapUV, float normalX, float normalY, float normalZ) {
IVertexBuilder.super.addVertex(x, y, z, 255, 255, 255, 255, texU, texV, overlayUV, lightmapUV, normalX, normalY, normalZ);
}
@Override
public IVertexBuilder tex(float u, float v) {
return builder.tex(u, v);
}
@Override
public IVertexBuilder pos(double x, double y, double z) {
return builder.pos(x, y, z);
}
@Override
public IVertexBuilder overlay(int u, int v) {
return builder.overlay(u, v);
}
@Override
public IVertexBuilder normal(float x, float y, float z) {
return builder.normal(x, y, z);
}
@Override
public IVertexBuilder lightmap(int u, int v) {
return builder.lightmap(u, v);
}
@Override
public void endVertex() {
builder.endVertex();
}
@Override
public IVertexBuilder color(int red, int green, int blue, int alpha) {
return builder.color(0, 150, 255, 135);
}
};
}, light);
}
Aggregations