use of de.budschie.bmorph.morph.MorphItem in project BudschieMorphMod by Budschie.
the class MorphCapabilityFullSynchronizer method decode.
@Override
public MorphPacket decode(PacketBuffer buffer) {
UUID playerUUID = buffer.readUniqueId();
// Hmmm yeah the floor is made out of floor
MorphList morphList = new MorphList();
morphList.deserializePacket(buffer);
FavouriteList favouriteList = new FavouriteList(morphList);
favouriteList.deserializePacket(buffer);
Optional<MorphItem> toMorph = Optional.empty();
Optional<Integer> entityIndex = Optional.empty();
boolean hasMorph = buffer.readBoolean(), hasIndex = buffer.readBoolean();
if (hasMorph)
toMorph = Optional.of(MorphHandler.deserializeMorphItem(buffer.readCompoundTag()));
if (hasIndex)
entityIndex = Optional.of(buffer.readInt());
int amountOfAbilities = buffer.readInt();
ArrayList<String> abilities = new ArrayList<>(amountOfAbilities);
for (int i = 0; i < amountOfAbilities; i++) abilities.add(buffer.readString());
return new MorphPacket(toMorph, entityIndex, morphList, favouriteList, abilities, playerUUID);
}
use of de.budschie.bmorph.morph.MorphItem 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.morph.MorphItem 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.morph.MorphItem in project BudschieMorphMod by Budschie.
the class FilteredSimpleMorphGui method showGui.
@Override
public void showGui() {
@SuppressWarnings("resource") LazyOptional<IMorphCapability> cap = Minecraft.getInstance().player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
if (cap.isPresent()) {
IMorphCapability resolved = cap.resolve().get();
// Create a list of indices of morphs
List<Integer> morphList = new ArrayList<>();
// This is dumb
for (int i = 0; i < resolved.getMorphList().getMorphArrayList().size(); i++) {
if (filter.test(resolved, i))
morphList.add(i);
}
morphWidgets.add(new MorphWidget(null, false, -1));
HashMap<EntityType<?>, Pair<MorphWidget, Integer>> currentWidgetHeads = new HashMap<>();
for (int i = 0; i < morphList.size(); i++) {
int indexOfMorph = morphList.get(i);
MorphItem item = resolved.getMorphList().getMorphArrayList().get(indexOfMorph);
MorphWidget widget = new MorphWidget(item, resolved.getFavouriteList().containsMorphItem(item), indexOfMorph);
Pair<MorphWidget, Integer> currentWidgetHead = currentWidgetHeads.get(widget.morphItem.getEntityType());
// Check if there is a head.
if (currentWidgetHead != null) {
// There is a head, add to head
MorphWidget head = currentWidgetHead.getA();
head.child = widget;
} else {
// No head, add to widget list
morphWidgets.add(widget);
}
// Set as new entity head
currentWidgetHeads.put(widget.morphItem.getEntityType(), new Pair<>(widget, currentWidgetHead == null ? 0 : currentWidgetHead.getB() + 1));
}
for (int i = 1; i < morphWidgets.size(); i++) {
MorphWidget widget = morphWidgets.get(i);
Pair<MorphWidget, Integer> currentWidgetHead = currentWidgetHeads.get(widget.morphItem.getEntityType());
widget.depth = currentWidgetHead.getB();
}
}
}
use of de.budschie.bmorph.morph.MorphItem in project BudschieMorphMod by Budschie.
the class MorphCommand method addMorph.
private static int addMorph(List<ServerPlayerEntity> entities, ResourceLocation rs, CompoundNBT nbtData) {
MorphItem morphItemToAdd = MorphManagerHandlers.FALLBACK.createMorph(ForgeRegistries.ENTITIES.getValue(rs), nbtData, null, true);
for (ServerPlayerEntity entity : entities) {
IMorphCapability capability = entity.getCapability(MorphCapabilityAttacher.MORPH_CAP).resolve().get();
if (capability.getMorphList().contains(morphItemToAdd))
entity.sendMessage(new StringTextComponent(TextFormatting.RED + "You may not add a morph to your list that is already present."), new UUID(0, 0));
else {
entity.sendMessage(new StringTextComponent("Added " + rs.toString() + " with its NBT data to your morph list."), new UUID(0, 0));
capability.addToMorphList(morphItemToAdd);
capability.syncMorphAcquisition(entity, morphItemToAdd);
}
}
return 0;
}
Aggregations