mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-12-17 23:48:00 +01:00
Refactor the entity predicates
This commit is contained in:
parent
2aea8791a0
commit
da824ffe7d
25 changed files with 86 additions and 121 deletions
|
@ -1,54 +1,31 @@
|
||||||
package com.minelittlepony.unicopia;
|
package com.minelittlepony.unicopia;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import java.util.function.Predicate;
|
||||||
import com.minelittlepony.unicopia.entity.Ponylike;
|
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.entity.CloudEntity;
|
||||||
|
import com.minelittlepony.unicopia.entity.Ponylike;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.ItemEntity;
|
import net.minecraft.entity.ItemEntity;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
|
||||||
public interface EquinePredicates {
|
public interface EquinePredicates {
|
||||||
Predicate<PlayerEntity> INTERACT_WITH_CLOUDS = player -> {
|
Predicate<Entity> IS_CLOUD = e -> e instanceof CloudEntity;
|
||||||
return player != null && Pony.of(player).getSpecies().canInteractWithClouds();
|
Predicate<Entity> IS_PLAYER = e -> e instanceof PlayerEntity;
|
||||||
};
|
Predicate<Entity> IS_VALID_ITEM = entity -> entity instanceof ItemEntity && entity.isAlive() && entity.age > 1;
|
||||||
|
|
||||||
Predicate<Entity> MAGI = entity -> {
|
Predicate<Entity> RACE_INTERACT_WITH_CLOUDS = entity -> Ponylike.of(entity).getSpecies().canInteractWithClouds();
|
||||||
return entity instanceof PlayerEntity && Pony.of((PlayerEntity)entity).getSpecies().canCast();
|
|
||||||
};
|
|
||||||
|
|
||||||
Predicate<Entity> ITEMS = entity -> {
|
Predicate<Entity> PLAYER_UNICORN = IS_PLAYER.and(entity -> Ponylike.of(entity).getSpecies().canCast());
|
||||||
return entity instanceof ItemEntity && entity.isAlive() && entity.age > 1;
|
Predicate<Entity> PLAYER_CHANGELING = IS_PLAYER.and(entity -> Ponylike.of(entity).getSpecies() == Race.CHANGELING);
|
||||||
};
|
Predicate<Entity> PLAYER_PEGASUS = IS_PLAYER.and(entity -> ((PlayerEntity)entity).abilities.creativeMode || RACE_INTERACT_WITH_CLOUDS.test(entity));
|
||||||
|
|
||||||
Predicate<ItemEntity> ITEM_INTERACT_WITH_CLOUDS = item -> {
|
Predicate<Entity> ITEM_INTERACT_WITH_CLOUDS = IS_VALID_ITEM.and(RACE_INTERACT_WITH_CLOUDS);
|
||||||
return ITEMS.test(item) && Ponylike.of(item).getSpecies().canInteractWithClouds();
|
|
||||||
};
|
|
||||||
|
|
||||||
Predicate<Entity> ENTITY_INTERACT_WITH_CLOUDS = entity -> {
|
Predicate<Entity> ENTITY_INTERACT_WITH_CLOUDS = PLAYER_PEGASUS.or(ITEM_INTERACT_WITH_CLOUDS);
|
||||||
return entity != null && (
|
Predicate<Entity> ENTITY_WALK_ON_CLOUDS = entity -> entity instanceof LivingEntity && CloudEntity.getFeatherEnchantStrength((LivingEntity)entity) > 0;
|
||||||
(entity instanceof PlayerEntity && INTERACT_WITH_CLOUDS.test((PlayerEntity)entity))
|
|
||||||
|| (entity instanceof ItemEntity && ITEM_INTERACT_WITH_CLOUDS.test((ItemEntity)entity))
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
Predicate<Entity> BUGGY = entity -> {
|
Predicate<Entity> ENTITY_INTERACT_WITH_CLOUD_BLOCKS = IS_CLOUD.or(PLAYER_PEGASUS).or(ENTITY_WALK_ON_CLOUDS).or(ITEM_INTERACT_WITH_CLOUDS).or(entity -> {
|
||||||
return entity instanceof PlayerEntity
|
return entity != null && EquinePredicates.ENTITY_INTERACT_WITH_CLOUD_BLOCKS.test(entity.getVehicle());
|
||||||
&& Pony.of((PlayerEntity)entity).getSpecies() == Race.CHANGELING;
|
});
|
||||||
};
|
|
||||||
|
|
||||||
static PlayerEntity getPlayerFromEntity(Entity entity) {
|
|
||||||
if (entity instanceof PlayerEntity) {
|
|
||||||
return (PlayerEntity) entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof ItemEntity) {
|
|
||||||
ItemEntity item = (ItemEntity)entity;
|
|
||||||
if (item.getOwner() != null) {
|
|
||||||
return item.getEntityWorld().getPlayerByUuid(item.getOwner());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class DiamondDoorBlock extends AbstractDoorBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean canOpen(@Nullable PlayerEntity player) {
|
protected boolean canOpen(@Nullable PlayerEntity player) {
|
||||||
return EquinePredicates.MAGI.test(player);
|
return EquinePredicates.PLAYER_UNICORN.test(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -170,7 +170,7 @@ public class SlimeDropBlock extends Block implements Climbable {
|
||||||
if (entity instanceof LivingEntity && !entity.removed) {
|
if (entity instanceof LivingEntity && !entity.removed) {
|
||||||
LivingEntity living = (LivingEntity)entity;
|
LivingEntity living = (LivingEntity)entity;
|
||||||
|
|
||||||
if (!EquinePredicates.BUGGY.test(living) && living.getHealth() > 0) {
|
if (!EquinePredicates.PLAYER_CHANGELING.test(living) && living.getHealth() > 0) {
|
||||||
living.damage(MagicalDamageSource.ACID, 1);
|
living.damage(MagicalDamageSource.ACID, 1);
|
||||||
living.slowMovement(state, new Vec3d(0.25D, 0.05000000074505806D, 0.25D));
|
living.slowMovement(state, new Vec3d(0.25D, 0.05000000074505806D, 0.25D));
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.minelittlepony.unicopia.client;
|
package com.minelittlepony.unicopia.client;
|
||||||
|
|
||||||
import static com.minelittlepony.unicopia.EquinePredicates.MAGI;
|
import static com.minelittlepony.unicopia.EquinePredicates.PLAYER_UNICORN;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ public class UnicopiaClient implements ClientModInitializer {
|
||||||
}, UItems.APPLE_LEAVES);
|
}, UItems.APPLE_LEAVES);
|
||||||
ColorProviderRegistry.BLOCK.register(UnicopiaClient::getLeavesColor, UBlocks.APPLE_LEAVES);
|
ColorProviderRegistry.BLOCK.register(UnicopiaClient::getLeavesColor, UBlocks.APPLE_LEAVES);
|
||||||
ColorProviderRegistry.ITEM.register((stack, tint) -> {
|
ColorProviderRegistry.ITEM.register((stack, tint) -> {
|
||||||
if (MAGI.test(MinecraftClient.getInstance().player)) {
|
if (PLAYER_UNICORN.test(MinecraftClient.getInstance().player)) {
|
||||||
return SpellRegistry.instance().getSpellTintFromStack(stack);
|
return SpellRegistry.instance().getSpellTintFromStack(stack);
|
||||||
}
|
}
|
||||||
return 0xFFFFFF;
|
return 0xFFFFFF;
|
||||||
|
|
|
@ -157,7 +157,7 @@ public class SpellBookContainer extends Container {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUse(PlayerEntity player) {
|
public boolean canUse(PlayerEntity player) {
|
||||||
return EquinePredicates.MAGI.test(player);
|
return EquinePredicates.PLAYER_UNICORN.test(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SpellbookSlot extends Slot {
|
public static class SpellbookSlot extends Slot {
|
||||||
|
|
|
@ -28,6 +28,7 @@ import net.minecraft.entity.EntityPose;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.entity.ItemEntity;
|
import net.minecraft.entity.ItemEntity;
|
||||||
import net.minecraft.entity.LightningEntity;
|
import net.minecraft.entity.LightningEntity;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.MovementType;
|
import net.minecraft.entity.MovementType;
|
||||||
import net.minecraft.entity.SpawnType;
|
import net.minecraft.entity.SpawnType;
|
||||||
import net.minecraft.entity.damage.DamageSource;
|
import net.minecraft.entity.damage.DamageSource;
|
||||||
|
@ -154,7 +155,7 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, InAnimate
|
||||||
@Override
|
@Override
|
||||||
public void pushAwayFrom(Entity other) {
|
public void pushAwayFrom(Entity other) {
|
||||||
if (other instanceof PlayerEntity) {
|
if (other instanceof PlayerEntity) {
|
||||||
if (EquinePredicates.INTERACT_WITH_CLOUDS.test((PlayerEntity)other)) {
|
if (EquinePredicates.PLAYER_PEGASUS.test(other)) {
|
||||||
super.pushAwayFrom(other);
|
super.pushAwayFrom(other);
|
||||||
}
|
}
|
||||||
} else if (other instanceof CloudEntity) {
|
} else if (other instanceof CloudEntity) {
|
||||||
|
@ -429,7 +430,7 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, InAnimate
|
||||||
ItemStack stack = player.getMainHandStack();
|
ItemStack stack = player.getMainHandStack();
|
||||||
|
|
||||||
boolean canFly = EnchantmentHelper.getEnchantments(stack).containsKey(Enchantments.FEATHER_FALLING)
|
boolean canFly = EnchantmentHelper.getEnchantments(stack).containsKey(Enchantments.FEATHER_FALLING)
|
||||||
|| EquinePredicates.INTERACT_WITH_CLOUDS.test(player);
|
|| EquinePredicates.PLAYER_PEGASUS.test(player);
|
||||||
boolean stat = getStationary();
|
boolean stat = getStationary();
|
||||||
|
|
||||||
if (stat || canFly) {
|
if (stat || canFly) {
|
||||||
|
@ -479,7 +480,7 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, InAnimate
|
||||||
|
|
||||||
private boolean entityIsFloatingItem(Entity e) {
|
private boolean entityIsFloatingItem(Entity e) {
|
||||||
return e instanceof ItemEntity
|
return e instanceof ItemEntity
|
||||||
&& EquinePredicates.ITEM_INTERACT_WITH_CLOUDS.test((ItemEntity)e);
|
&& EquinePredicates.ITEM_INTERACT_WITH_CLOUDS.test(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -575,15 +576,15 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, InAnimate
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity instanceof PlayerEntity) {
|
if (entity instanceof LivingEntity) {
|
||||||
return getFeatherEnchantStrength((PlayerEntity)entity);
|
return getFeatherEnchantStrength((LivingEntity)entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getFeatherEnchantStrength(PlayerEntity player) {
|
public static int getFeatherEnchantStrength(LivingEntity entity) {
|
||||||
for (ItemStack stack : player.getArmorItems()) {
|
for (ItemStack stack : entity.getArmorItems()) {
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(stack);
|
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(stack);
|
||||||
if (enchantments.containsKey(Enchantments.FEATHER_FALLING)) {
|
if (enchantments.containsKey(Enchantments.FEATHER_FALLING)) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class ConstructionCloudEntity extends CloudEntity {
|
||||||
@Override
|
@Override
|
||||||
public ActionResult interactAt(PlayerEntity player, Vec3d vec, Hand hand) {
|
public ActionResult interactAt(PlayerEntity player, Vec3d vec, Hand hand) {
|
||||||
if (!(hasPassengers() || isConnectedThroughVehicle(player)) && hand == Hand.MAIN_HAND) {
|
if (!(hasPassengers() || isConnectedThroughVehicle(player)) && hand == Hand.MAIN_HAND) {
|
||||||
if (EquinePredicates.INTERACT_WITH_CLOUDS.test(player)) {
|
if (EquinePredicates.PLAYER_PEGASUS.test(player)) {
|
||||||
|
|
||||||
if (player.getItemUseTime() > 0) {
|
if (player.getItemUseTime() > 0) {
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class CuccoonEntity extends LivingEntity implements IMagicals, InAnimate
|
||||||
@Override
|
@Override
|
||||||
public boolean damage(DamageSource source, float amount) {
|
public boolean damage(DamageSource source, float amount) {
|
||||||
|
|
||||||
if (EquinePredicates.BUGGY.test(source.getSource())) {
|
if (EquinePredicates.PLAYER_CHANGELING.test(source.getSource())) {
|
||||||
amount = 0;
|
amount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ public class CuccoonEntity extends LivingEntity implements IMagicals, InAnimate
|
||||||
&& !entity.isSneaking()
|
&& !entity.isSneaking()
|
||||||
&& !hasPassengers()
|
&& !hasPassengers()
|
||||||
&& entity instanceof LivingEntity
|
&& entity instanceof LivingEntity
|
||||||
&& !EquinePredicates.BUGGY.test(entity);
|
&& !EquinePredicates.PLAYER_CHANGELING.test(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -149,7 +149,7 @@ public class CuccoonEntity extends LivingEntity implements IMagicals, InAnimate
|
||||||
@Override
|
@Override
|
||||||
public ActionResult interactAt(PlayerEntity player, Vec3d vec, Hand hand) {
|
public ActionResult interactAt(PlayerEntity player, Vec3d vec, Hand hand) {
|
||||||
|
|
||||||
if (hand == Hand.MAIN_HAND && EquinePredicates.BUGGY.test(player)) {
|
if (hand == Hand.MAIN_HAND && EquinePredicates.PLAYER_CHANGELING.test(player)) {
|
||||||
|
|
||||||
if (hasPassengers()) {
|
if (hasPassengers()) {
|
||||||
Entity passenger = getPrimaryPassenger();
|
Entity passenger = getPrimaryPassenger();
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class RacingCloudEntity extends CloudEntity {
|
||||||
@Override
|
@Override
|
||||||
public ActionResult interactAt(PlayerEntity player, Vec3d vec, Hand hand) {
|
public ActionResult interactAt(PlayerEntity player, Vec3d vec, Hand hand) {
|
||||||
if (!(hasPassengers() || isConnectedThroughVehicle(player)) && hand == Hand.MAIN_HAND) {
|
if (!(hasPassengers() || isConnectedThroughVehicle(player)) && hand == Hand.MAIN_HAND) {
|
||||||
if (EquinePredicates.INTERACT_WITH_CLOUDS.test(player)) {
|
if (EquinePredicates.PLAYER_PEGASUS.test(player)) {
|
||||||
if (!getStationary()) {
|
if (!getStationary()) {
|
||||||
player.startRiding(this);
|
player.startRiding(this);
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
|
|
|
@ -163,7 +163,7 @@ public class SpellbookEntity extends MobEntity implements NameableContainerFacto
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EquinePredicates.MAGI.test(player)) {
|
if (EquinePredicates.PLAYER_UNICORN.test(player)) {
|
||||||
|
|
||||||
player.playSound(SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, 2, 1);
|
player.playSound(SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, 2, 1);
|
||||||
|
|
||||||
|
|
|
@ -287,7 +287,7 @@ public class SpellcastEntity extends MobEntityWithAi implements IMagicals, Caste
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult interactAt(PlayerEntity player, Vec3d vec, Hand hand) {
|
public ActionResult interactAt(PlayerEntity player, Vec3d vec, Hand hand) {
|
||||||
if (EquinePredicates.MAGI.test(player)) {
|
if (EquinePredicates.PLAYER_UNICORN.test(player)) {
|
||||||
ItemStack currentItem = player.getStackInHand(Hand.MAIN_HAND);
|
ItemStack currentItem = player.getStackInHand(Hand.MAIN_HAND);
|
||||||
|
|
||||||
if (currentItem != null
|
if (currentItem != null
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class CloudFenceBlock extends FenceBlock implements Gas {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) {
|
public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) {
|
||||||
return getGasType(state) == CloudType.NORMAL;
|
return getGasType(state).isTranslucent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package com.minelittlepony.unicopia.gas;
|
package com.minelittlepony.unicopia.gas;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.EquinePredicates;
|
import com.minelittlepony.unicopia.EquinePredicates;
|
||||||
import com.minelittlepony.unicopia.entity.CloudEntity;
|
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.ItemEntity;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
|
||||||
public interface CloudInteractionContext {
|
public interface CloudInteractionContext {
|
||||||
|
@ -23,32 +20,34 @@ public interface CloudInteractionContext {
|
||||||
|
|
||||||
boolean canTouch(CloudType type);
|
boolean canTouch(CloudType type);
|
||||||
|
|
||||||
|
interface Holder extends CloudInteractionContext {
|
||||||
|
CloudInteractionContext getCloudInteractionContext();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default boolean isPlayer() {
|
||||||
|
return getCloudInteractionContext().isPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default boolean isPegasis() {
|
||||||
|
return getCloudInteractionContext().isPegasis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default boolean canTouch(CloudType type) {
|
||||||
|
return getCloudInteractionContext().canTouch(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Impl implements CloudInteractionContext {
|
class Impl implements CloudInteractionContext {
|
||||||
private static final CloudInteractionContext EMPTY = type -> false;
|
public static final CloudInteractionContext EMPTY = type -> true;
|
||||||
|
|
||||||
private final boolean isPlayer;
|
private final boolean isPlayer;
|
||||||
private final boolean isPegasis;
|
private final boolean isPegasis;
|
||||||
|
|
||||||
private Impl(Entity entity) {
|
private Impl(Entity entity) {
|
||||||
this.isPlayer = entity instanceof PlayerEntity;
|
this.isPlayer = entity instanceof PlayerEntity;
|
||||||
this.isPegasis = isPegasis(entity);
|
this.isPegasis = EquinePredicates.ENTITY_INTERACT_WITH_CLOUD_BLOCKS.test(entity);
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isPegasis(Entity entity) {
|
|
||||||
if (entity instanceof PlayerEntity) {
|
|
||||||
return EquinePredicates.INTERACT_WITH_CLOUDS.test((PlayerEntity)entity)
|
|
||||||
|| (EquinePredicates.MAGI.test(entity) && CloudEntity.getFeatherEnchantStrength((PlayerEntity)entity) > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof ItemEntity) {
|
|
||||||
return EquinePredicates.ITEM_INTERACT_WITH_CLOUDS.test((ItemEntity)entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof CloudEntity && entity.hasVehicle()) {
|
|
||||||
return isPegasis(entity.getVehicle());
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -58,7 +58,7 @@ public interface Gas {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EquinePredicates.INTERACT_WITH_CLOUDS.apply(player)) {
|
if (!EquinePredicates.PLAYER_PEGASUS.test(player)) {
|
||||||
return type != CloudType.ENCHANTED;
|
return type != CloudType.ENCHANTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class BagOfHoldingItem extends Item implements MagicalItem {
|
||||||
@Override
|
@Override
|
||||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
||||||
|
|
||||||
if (!EquinePredicates.MAGI.test(player)) {
|
if (!EquinePredicates.PLAYER_UNICORN.test(player)) {
|
||||||
return super.use(world, player, hand);
|
return super.use(world, player, hand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ public class BagOfHoldingItem extends Item implements MagicalItem {
|
||||||
|
|
||||||
Box box = new Box(pos.offset(bhit.getSide())).expand(0.5);
|
Box box = new Box(pos.offset(bhit.getSide())).expand(0.5);
|
||||||
|
|
||||||
List<Entity> itemsAround = world.getEntities(player, box, EquinePredicates.ITEMS);
|
List<Entity> itemsAround = world.getEntities(player, box, EquinePredicates.IS_VALID_ITEM);
|
||||||
|
|
||||||
if (itemsAround.size() > 0) {
|
if (itemsAround.size() > 0) {
|
||||||
BagOfHoldingInventory inventory = BagOfHoldingInventory.getInventoryFromStack(stack);
|
BagOfHoldingInventory inventory = BagOfHoldingInventory.getInventoryFromStack(stack);
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class EnchantedStaffItem extends StaffItem implements Affine, TossableIte
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
||||||
if (EquinePredicates.MAGI.test(player) && hand == Hand.MAIN_HAND) {
|
if (EquinePredicates.PLAYER_UNICORN.test(player) && hand == Hand.MAIN_HAND) {
|
||||||
ItemStack itemstack = player.getStackInHand(hand);
|
ItemStack itemstack = player.getStackInHand(hand);
|
||||||
|
|
||||||
player.swingHand(hand);
|
player.swingHand(hand);
|
||||||
|
@ -64,8 +64,7 @@ public class EnchantedStaffItem extends StaffItem implements Affine, TossableIte
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStoppedUsing(ItemStack itemstack, World world, LivingEntity entity, int timeLeft) {
|
public void onStoppedUsing(ItemStack itemstack, World world, LivingEntity entity, int timeLeft) {
|
||||||
if (EquinePredicates.MAGI.test(entity) && entity instanceof PlayerEntity) {
|
if (EquinePredicates.PLAYER_UNICORN.test(entity)) {
|
||||||
|
|
||||||
int i = getMaxUseTime(itemstack) - timeLeft;
|
int i = getMaxUseTime(itemstack) - timeLeft;
|
||||||
|
|
||||||
if (i > 10 && canBeThrown(itemstack)) {
|
if (i > 10 && canBeThrown(itemstack)) {
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class MagicGemItem extends Item implements Castable {
|
||||||
Hand hand = context.getHand();
|
Hand hand = context.getHand();
|
||||||
PlayerEntity player = context.getPlayer();
|
PlayerEntity player = context.getPlayer();
|
||||||
|
|
||||||
if (hand != Hand.MAIN_HAND || !EquinePredicates.MAGI.test(player)) {
|
if (hand != Hand.MAIN_HAND || !EquinePredicates.PLAYER_UNICORN.test(player)) {
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ public class MagicGemItem extends Item implements Castable {
|
||||||
|
|
||||||
ItemStack stack = player.getStackInHand(hand);
|
ItemStack stack = player.getStackInHand(hand);
|
||||||
|
|
||||||
if (!EquinePredicates.MAGI.test(player)) {
|
if (!EquinePredicates.PLAYER_UNICORN.test(player)) {
|
||||||
return new TypedActionResult<>(ActionResult.PASS, stack);
|
return new TypedActionResult<>(ActionResult.PASS, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.function.Predicate;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
@ -13,9 +14,9 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
public class PredicatedBlockItem extends BlockItem {
|
public class PredicatedBlockItem extends BlockItem {
|
||||||
|
|
||||||
private final Predicate<PlayerEntity> abilityTest;
|
private final Predicate<Entity> abilityTest;
|
||||||
|
|
||||||
public PredicatedBlockItem(Block block, Item.Settings settings, Predicate<PlayerEntity> abilityTest) {
|
public PredicatedBlockItem(Block block, Item.Settings settings, Predicate<Entity> abilityTest) {
|
||||||
super(block, settings);
|
super(block, settings);
|
||||||
|
|
||||||
this.abilityTest = abilityTest;
|
this.abilityTest = abilityTest;
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class SpellbookItem extends BookItem {
|
||||||
@Nullable
|
@Nullable
|
||||||
PlayerEntity player = context.getPlayer();
|
PlayerEntity player = context.getPlayer();
|
||||||
|
|
||||||
if (!context.getWorld().isClient && EquinePredicates.MAGI.test(player)) {
|
if (!context.getWorld().isClient && EquinePredicates.PLAYER_UNICORN.test(player)) {
|
||||||
BlockPos pos = context.getBlockPos().offset(context.getSide());
|
BlockPos pos = context.getBlockPos().offset(context.getSide());
|
||||||
|
|
||||||
double diffX = player.getX() - (pos.getX() + 0.5);
|
double diffX = player.getX() - (pos.getX() + 0.5);
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class StaffItem extends SwordItem {
|
||||||
public boolean postHit(ItemStack stack, LivingEntity entity, LivingEntity attacker) {
|
public boolean postHit(ItemStack stack, LivingEntity entity, LivingEntity attacker) {
|
||||||
super.postHit(stack, entity, attacker);
|
super.postHit(stack, entity, attacker);
|
||||||
|
|
||||||
if (EquinePredicates.MAGI.test(entity)) {
|
if (EquinePredicates.PLAYER_UNICORN.test(entity)) {
|
||||||
return castContainedEffect(stack, entity, attacker);
|
return castContainedEffect(stack, entity, attacker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,13 +45,13 @@ public interface UItems {
|
||||||
CloudPlacerItem CONSTRUCTION_CLOUD_SPAWNER = register(new CloudPlacerItem(UEntities.CONSTRUCTION_CLOUD), "construction_cloud_spawner");
|
CloudPlacerItem CONSTRUCTION_CLOUD_SPAWNER = register(new CloudPlacerItem(UEntities.CONSTRUCTION_CLOUD), "construction_cloud_spawner");
|
||||||
CloudPlacerItem WILD_CLOUD_SPAWNER = register(new CloudPlacerItem(UEntities.WILD_CLOUD), "wild_cloud_spawner");
|
CloudPlacerItem WILD_CLOUD_SPAWNER = register(new CloudPlacerItem(UEntities.WILD_CLOUD), "wild_cloud_spawner");
|
||||||
|
|
||||||
Item CLOUD_BLOCK = register(new PredicatedBlockItem(UBlocks.CLOUD_BLOCK, new Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "cloud_block");
|
Item CLOUD_BLOCK = register(new PredicatedBlockItem(UBlocks.CLOUD_BLOCK, new Settings().group(ItemGroup.MATERIALS), PLAYER_PEGASUS), "cloud_block");
|
||||||
Item ENCHANTED_CLOUD_BLOCK = register(new PredicatedBlockItem(UBlocks.ENCHANTED_CLOUD_BLOCK, new Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "enchanted_cloud_block");
|
Item ENCHANTED_CLOUD_BLOCK = register(new PredicatedBlockItem(UBlocks.ENCHANTED_CLOUD_BLOCK, new Settings().group(ItemGroup.MATERIALS), PLAYER_PEGASUS), "enchanted_cloud_block");
|
||||||
Item DENSE_CLOUD_BLOCK = register(new PredicatedBlockItem(UBlocks.DENSE_CLOUD_BLOCK, new Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "dense_cloud_block");
|
Item DENSE_CLOUD_BLOCK = register(new PredicatedBlockItem(UBlocks.DENSE_CLOUD_BLOCK, new Settings().group(ItemGroup.MATERIALS), PLAYER_PEGASUS), "dense_cloud_block");
|
||||||
|
|
||||||
Item CLOUD_STAIRS = register(new PredicatedBlockItem(UBlocks.CLOUD_STAIRS, new Settings().group(ItemGroup.BUILDING_BLOCKS), INTERACT_WITH_CLOUDS), "cloud_stairs");
|
Item CLOUD_STAIRS = register(new PredicatedBlockItem(UBlocks.CLOUD_STAIRS, new Settings().group(ItemGroup.BUILDING_BLOCKS), PLAYER_PEGASUS), "cloud_stairs");
|
||||||
Item CLOUD_FENCE = register(new PredicatedBlockItem(UBlocks.CLOUD_FENCE, new Settings().group(ItemGroup.DECORATIONS), INTERACT_WITH_CLOUDS), "cloud_fence");
|
Item CLOUD_FENCE = register(new PredicatedBlockItem(UBlocks.CLOUD_FENCE, new Settings().group(ItemGroup.DECORATIONS), PLAYER_PEGASUS), "cloud_fence");
|
||||||
Item CLOUD_ANVIL = register(new PredicatedBlockItem(UBlocks.CLOUD_ANVIL, new Settings().group(ItemGroup.DECORATIONS), INTERACT_WITH_CLOUDS), "cloud_anvil");
|
Item CLOUD_ANVIL = register(new PredicatedBlockItem(UBlocks.CLOUD_ANVIL, new Settings().group(ItemGroup.DECORATIONS), PLAYER_PEGASUS), "cloud_anvil");
|
||||||
|
|
||||||
Item MUSIC_DISC_CRUSADE = register(createRecord(USounds.RECORD_CRUSADE), "music_disc_crusade");
|
Item MUSIC_DISC_CRUSADE = register(createRecord(USounds.RECORD_CRUSADE), "music_disc_crusade");
|
||||||
Item MUSIC_DISC_PET = register(createRecord(USounds.RECORD_PET), "music_disc_pet");
|
Item MUSIC_DISC_PET = register(createRecord(USounds.RECORD_PET), "music_disc_pet");
|
||||||
|
@ -72,9 +72,9 @@ public interface UItems {
|
||||||
|
|
||||||
Item SUGAR_BLOCK = register(new BlockItem(UBlocks.SUGAR_BLOCK, new Settings().group(ItemGroup.BUILDING_BLOCKS)), "sugar_block");
|
Item SUGAR_BLOCK = register(new BlockItem(UBlocks.SUGAR_BLOCK, new Settings().group(ItemGroup.BUILDING_BLOCKS)), "sugar_block");
|
||||||
|
|
||||||
Item CLOUD_SLAB = register(new PredicatedBlockItem(UBlocks.CLOUD_SLAB, new Settings().group(ItemGroup.BUILDING_BLOCKS), INTERACT_WITH_CLOUDS), "cloud_slab");
|
Item CLOUD_SLAB = register(new PredicatedBlockItem(UBlocks.CLOUD_SLAB, new Settings().group(ItemGroup.BUILDING_BLOCKS), PLAYER_PEGASUS), "cloud_slab");
|
||||||
Item ENCHANTED_CLOUD_SLAB = register(new PredicatedBlockItem(UBlocks.ENCHANTED_CLOUD_SLAB, new Settings().group(ItemGroup.BUILDING_BLOCKS), INTERACT_WITH_CLOUDS), "enchanted_cloud_slab");
|
Item ENCHANTED_CLOUD_SLAB = register(new PredicatedBlockItem(UBlocks.ENCHANTED_CLOUD_SLAB, new Settings().group(ItemGroup.BUILDING_BLOCKS), PLAYER_PEGASUS), "enchanted_cloud_slab");
|
||||||
Item DENSE_CLOUD_SLAB = register(new PredicatedBlockItem(UBlocks.DENSE_CLOUD_SLAB, new Settings().group(ItemGroup.BUILDING_BLOCKS), INTERACT_WITH_CLOUDS), "dense_cloud_slab");
|
Item DENSE_CLOUD_SLAB = register(new PredicatedBlockItem(UBlocks.DENSE_CLOUD_SLAB, new Settings().group(ItemGroup.BUILDING_BLOCKS), PLAYER_PEGASUS), "dense_cloud_slab");
|
||||||
|
|
||||||
MagicGemItem GEM = register(new MagicGemItem(new Settings().maxCount(16).group(ItemGroup.BREWING)), "gem");
|
MagicGemItem GEM = register(new MagicGemItem(new Settings().maxCount(16).group(ItemGroup.BREWING)), "gem");
|
||||||
MagicGemItem CORRUPTED_GEM = register(new CursedMagicGemItem(new Settings().maxCount(16).group(ItemGroup.BREWING)), "corrupted_gem");
|
MagicGemItem CORRUPTED_GEM = register(new CursedMagicGemItem(new Settings().maxCount(16).group(ItemGroup.BREWING)), "corrupted_gem");
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class CasterUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
static Stream<Caster<?>> findAllSpellsInRange(Caster<?> source, Box bb) {
|
static Stream<Caster<?>> findAllSpellsInRange(Caster<?> source, Box bb) {
|
||||||
return source.getWorld().getEntities(source.getEntity(), bb, e -> !e.removed && (e instanceof Caster || EquinePredicates.MAGI.test(e))).stream()
|
return source.getWorld().getEntities(source.getEntity(), bb, e -> !e.removed && (e instanceof Caster || EquinePredicates.PLAYER_UNICORN.test(e))).stream()
|
||||||
.map(CasterUtils::toCaster)
|
.map(CasterUtils::toCaster)
|
||||||
.filter(o -> o.isPresent() && o.get() != source)
|
.filter(o -> o.isPresent() && o.get() != source)
|
||||||
.map(Optional::get);
|
.map(Optional::get);
|
||||||
|
|
|
@ -179,7 +179,7 @@ public class FireSpell extends AbstractSpell.RangedAreaSpell implements Useable,
|
||||||
|
|
||||||
protected boolean applyEntitySingle(Entity owner, World world, Entity e) {
|
protected boolean applyEntitySingle(Entity owner, World world, Entity e) {
|
||||||
if ((!e.equals(owner) ||
|
if ((!e.equals(owner) ||
|
||||||
(owner instanceof PlayerEntity && !EquinePredicates.MAGI.test(owner))) && !(e instanceof ItemEntity)
|
(owner instanceof PlayerEntity && !EquinePredicates.PLAYER_UNICORN.test(owner))) && !(e instanceof ItemEntity)
|
||||||
&& !(e instanceof IMagicals)) {
|
&& !(e instanceof IMagicals)) {
|
||||||
e.setOnFireFor(60);
|
e.setOnFireFor(60);
|
||||||
e.damage(getDamageCause(e, (LivingEntity)owner), 0.1f);
|
e.damage(getDamageCause(e, (LivingEntity)owner), 0.1f);
|
||||||
|
|
|
@ -95,7 +95,7 @@ public class ShieldSpell extends AbstractSpell.RangedAreaSpell implements Attach
|
||||||
|
|
||||||
Entity owner = source.getOwner();
|
Entity owner = source.getOwner();
|
||||||
|
|
||||||
boolean ownerIsValid = source.getAffinity() != Affinity.BAD && EquinePredicates.MAGI.test(owner);
|
boolean ownerIsValid = source.getAffinity() != Affinity.BAD && EquinePredicates.PLAYER_UNICORN.test(owner);
|
||||||
|
|
||||||
Vec3d origin = source.getOriginVector();
|
Vec3d origin = source.getOriginVector();
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,11 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.gas.CloudInteractionContext;
|
import com.minelittlepony.unicopia.gas.CloudInteractionContext;
|
||||||
import com.minelittlepony.unicopia.gas.CloudType;
|
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityContextImpl;
|
import net.minecraft.entity.EntityContextImpl;
|
||||||
|
|
||||||
@Mixin(EntityContextImpl.class)
|
@Mixin(EntityContextImpl.class)
|
||||||
abstract class MixinEntityContextImpl implements CloudInteractionContext {
|
abstract class MixinEntityContextImpl implements CloudInteractionContext.Holder {
|
||||||
private CloudInteractionContext cloudContext;
|
private CloudInteractionContext cloudContext;
|
||||||
|
|
||||||
@Inject(method = "<init>(Lnet/minecraft/entity/Entity;)V", at = @At("RETURN"))
|
@Inject(method = "<init>(Lnet/minecraft/entity/Entity;)V", at = @At("RETURN"))
|
||||||
|
@ -21,17 +19,7 @@ abstract class MixinEntityContextImpl implements CloudInteractionContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPlayer() {
|
public CloudInteractionContext getCloudInteractionContext() {
|
||||||
return cloudContext != null && cloudContext.isPlayer();
|
return cloudContext == null ? CloudInteractionContext.Impl.EMPTY : cloudContext;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPegasis() {
|
|
||||||
return cloudContext != null && cloudContext.isPegasis();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canTouch(CloudType type) {
|
|
||||||
return cloudContext != null && cloudContext.canTouch(type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue