mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-08 06:26:43 +01:00
Rename the fairy into a twittermite
This commit is contained in:
parent
7ec631ddcd
commit
a8d2a28900
4 changed files with 25 additions and 14 deletions
|
@ -71,7 +71,7 @@ public interface URenderers {
|
||||||
EntityRendererRegistry.register(UEntities.BUTTERFLY, ButterflyEntityRenderer::new);
|
EntityRendererRegistry.register(UEntities.BUTTERFLY, ButterflyEntityRenderer::new);
|
||||||
EntityRendererRegistry.register(UEntities.FLOATING_ARTEFACT, FloatingArtefactEntityRenderer::new);
|
EntityRendererRegistry.register(UEntities.FLOATING_ARTEFACT, FloatingArtefactEntityRenderer::new);
|
||||||
EntityRendererRegistry.register(UEntities.CAST_SPELL, CastSpellEntityRenderer::new);
|
EntityRendererRegistry.register(UEntities.CAST_SPELL, CastSpellEntityRenderer::new);
|
||||||
EntityRendererRegistry.register(UEntities.FAIRY, FairyEntityRenderer::new);
|
EntityRendererRegistry.register(UEntities.TWITTERMITE, FairyEntityRenderer::new);
|
||||||
EntityRendererRegistry.register(UEntities.SPELLBOOK, SpellbookEntityRenderer::new);
|
EntityRendererRegistry.register(UEntities.SPELLBOOK, SpellbookEntityRenderer::new);
|
||||||
|
|
||||||
ColorProviderRegistry.ITEM.register((stack, i) -> i > 0 ? -1 : ((DyeableItem)stack.getItem()).getColor(stack), UItems.FRIENDSHIP_BRACELET);
|
ColorProviderRegistry.ITEM.register((stack, i) -> i > 0 ? -1 : ((DyeableItem)stack.getItem()).getColor(stack), UItems.FRIENDSHIP_BRACELET);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
|
import net.minecraft.nbt.NbtElement;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -29,33 +30,42 @@ public class EntityReference<T extends Entity> implements NbtSerialisable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the position the last known position of the assigned entity.
|
||||||
|
*/
|
||||||
public Optional<Vec3d> getPosition() {
|
public Optional<Vec3d> getPosition() {
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPresent(World world) {
|
public boolean isPresent(World world) {
|
||||||
T entity = get(world);
|
return getOrEmpty(world).isPresent();
|
||||||
return entity != null && !entity.isRemoved();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ifPresent(World world, Consumer<T> consumer) {
|
public void ifPresent(World world, Consumer<T> consumer) {
|
||||||
if (isPresent(world)) {
|
getOrEmpty(world).ifPresent(consumer);
|
||||||
consumer.accept(get(world));
|
}
|
||||||
}
|
|
||||||
|
@Nullable
|
||||||
|
public T get(World world) {
|
||||||
|
return getOrEmpty(world).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Nullable
|
public Optional<T> getOrEmpty(World world) {
|
||||||
public T get(World world) {
|
|
||||||
if (uuid != null && world instanceof ServerWorld) {
|
if (uuid != null && world instanceof ServerWorld) {
|
||||||
return (T)((ServerWorld)world).getEntity(uuid);
|
return Optional.ofNullable((T)((ServerWorld)world).getEntity(uuid)).filter(this::checkReference);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clientId != 0) {
|
if (clientId != 0) {
|
||||||
return (T)world.getEntityById(clientId);
|
return Optional.ofNullable((T)world.getEntityById(clientId)).filter(this::checkReference);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkReference(Entity e) {
|
||||||
|
pos = Optional.of(e.getPos());
|
||||||
|
return !e.isRemoved();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -72,7 +82,7 @@ public class EntityReference<T extends Entity> implements NbtSerialisable {
|
||||||
@Override
|
@Override
|
||||||
public void fromNBT(NbtCompound tag) {
|
public void fromNBT(NbtCompound tag) {
|
||||||
uuid = tag.containsUuid("uuid") ? tag.getUuid("uuid") : null;
|
uuid = tag.containsUuid("uuid") ? tag.getUuid("uuid") : null;
|
||||||
pos = tag.contains("pos") ? Optional.ofNullable(NbtSerialisable.readVector(tag.getList("pos", 6))) : Optional.empty();
|
pos = tag.contains("pos") ? Optional.ofNullable(NbtSerialisable.readVector(tag.getList("pos", NbtElement.DOUBLE_TYPE))) : Optional.empty();
|
||||||
clientId = tag.getInt("clientId");
|
clientId = tag.getInt("clientId");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public interface UEntities {
|
||||||
EntityType<CastSpellEntity> CAST_SPELL = register("cast_spell", FabricEntityTypeBuilder.create(SpawnGroup.MISC, CastSpellEntity::new)
|
EntityType<CastSpellEntity> CAST_SPELL = register("cast_spell", FabricEntityTypeBuilder.create(SpawnGroup.MISC, CastSpellEntity::new)
|
||||||
.trackRangeBlocks(200)
|
.trackRangeBlocks(200)
|
||||||
.dimensions(EntityDimensions.fixed(1, 0.4F)));
|
.dimensions(EntityDimensions.fixed(1, 0.4F)));
|
||||||
EntityType<FairyEntity> FAIRY = register("fairy", FabricEntityTypeBuilder.create(SpawnGroup.MISC, FairyEntity::new)
|
EntityType<FairyEntity> TWITTERMITE = register("twittermite", FabricEntityTypeBuilder.create(SpawnGroup.MISC, FairyEntity::new)
|
||||||
.trackRangeBlocks(200)
|
.trackRangeBlocks(200)
|
||||||
.dimensions(EntityDimensions.fixed(0.1F, 0.1F)));
|
.dimensions(EntityDimensions.fixed(0.1F, 0.1F)));
|
||||||
EntityType<SpellbookEntity> SPELLBOOK = register("spellbook", FabricEntityTypeBuilder.create(SpawnGroup.MISC, SpellbookEntity::new)
|
EntityType<SpellbookEntity> SPELLBOOK = register("spellbook", FabricEntityTypeBuilder.create(SpawnGroup.MISC, SpellbookEntity::new)
|
||||||
|
@ -46,7 +46,7 @@ public interface UEntities {
|
||||||
static void bootstrap() {
|
static void bootstrap() {
|
||||||
FabricDefaultAttributeRegistry.register(BUTTERFLY, ButterflyEntity.createButterflyAttributes());
|
FabricDefaultAttributeRegistry.register(BUTTERFLY, ButterflyEntity.createButterflyAttributes());
|
||||||
FabricDefaultAttributeRegistry.register(SPELLBOOK, SpellbookEntity.createMobAttributes());
|
FabricDefaultAttributeRegistry.register(SPELLBOOK, SpellbookEntity.createMobAttributes());
|
||||||
FabricDefaultAttributeRegistry.register(FAIRY, FairyEntity.createMobAttributes());
|
FabricDefaultAttributeRegistry.register(TWITTERMITE, FairyEntity.createMobAttributes());
|
||||||
|
|
||||||
final Predicate<BiomeSelectionContext> butterflySpawnable = BiomeSelectors.foundInOverworld()
|
final Predicate<BiomeSelectionContext> butterflySpawnable = BiomeSelectors.foundInOverworld()
|
||||||
.and(ctx -> ctx.getBiome().getPrecipitation() == Biome.Precipitation.RAIN);
|
.and(ctx -> ctx.getBiome().getPrecipitation() == Biome.Precipitation.RAIN);
|
||||||
|
|
|
@ -79,6 +79,7 @@
|
||||||
"block.unicopia.rocks": "Rocks",
|
"block.unicopia.rocks": "Rocks",
|
||||||
|
|
||||||
"entity.unicopia.butterfly": "Butterfly",
|
"entity.unicopia.butterfly": "Butterfly",
|
||||||
|
"entity.unicopia.twittermite": "Twittermite",
|
||||||
"entity.unicopia.cast_spell": "Cast Spell",
|
"entity.unicopia.cast_spell": "Cast Spell",
|
||||||
"entity.unicopia.cast_spell.by": "a spell cast by %s",
|
"entity.unicopia.cast_spell.by": "a spell cast by %s",
|
||||||
"entity.unicopia.spellbook": "Spellbook",
|
"entity.unicopia.spellbook": "Spellbook",
|
||||||
|
|
Loading…
Reference in a new issue