use of de.budschie.bmorph.capabilities.IMorphCapability in project BudschieMorphMod by Budschie.
the class Events method onPlayerTakingDamage.
@SubscribeEvent
public static void onPlayerTakingDamage(LivingDamageEvent event) {
if (event.getEntityLiving() instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) event.getEntityLiving();
LazyOptional<IMorphCapability> cap = player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
if (cap.isPresent()) {
IMorphCapability resolved = cap.resolve().get();
}
} else // Check if living is a Mob and therefore "evil"
if (event.getSource().getTrueSource() instanceof PlayerEntity && event.getEntityLiving() instanceof IMob && !event.getEntity().world.isRemote) {
PlayerEntity source = (PlayerEntity) event.getSource().getTrueSource();
LazyOptional<IMorphCapability> cap = source.getCapability(MorphCapabilityAttacher.MORPH_CAP);
aggro(cap.resolve().get(), ServerSetup.server.getGameRules().getInt(BMorphMod.MORPH_AGGRO_DURATION));
}
}
use of de.budschie.bmorph.capabilities.IMorphCapability 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.capabilities.IMorphCapability 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;
}
use of de.budschie.bmorph.capabilities.IMorphCapability in project BudschieMorphMod by Budschie.
the class MorphGuiHandler method onPressedKey.
@SubscribeEvent
public static void onPressedKey(ClientTickEvent event) {
if (event.phase == Phase.END) {
if (Minecraft.getInstance().world != null) {
if (!currentMorphGui.isPresent())
traverseToIndexAndSetGui();
if (ClientSetup.TOGGLE_MORPH_UI.isPressed()) {
if (guiHidden)
showGui();
else
hideGui();
}
if (canGuiBeDisplayed()) {
if (ClientSetup.SCROLL_DOWN_MORPH_UI.isPressed())
currentMorphGui.get().scroll(1);
if (ClientSetup.SCROLL_UP_MORPH_UI.isPressed())
currentMorphGui.get().scroll(-1);
if (ClientSetup.SCROLL_LEFT_MORPH_UI.isPressed())
currentMorphGui.get().horizontalScroll(-1);
if (ClientSetup.SCROLL_RIGHT_MORPH_UI.isPressed())
currentMorphGui.get().horizontalScroll(1);
if (ClientSetup.NEXT_MORPH_UI.isPressed()) {
currentIndex++;
currentIndex %= MorphGuiRegistry.REGISTRY.get().getValues().size();
traverseToIndexAndSetGui();
updateCurrentMorphUI();
}
if (ClientSetup.PREVIOUS_MORPH_UI.isPressed()) {
currentIndex--;
currentIndex %= MorphGuiRegistry.REGISTRY.get().getValues().size();
traverseToIndexAndSetGui();
updateCurrentMorphUI();
}
if (ClientSetup.TOGGLE_MORPH_FAVOURITE.isPressed()) {
LazyOptional<IMorphCapability> cap = Minecraft.getInstance().player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
if (cap.isPresent()) {
IMorphCapability resolved = cap.resolve().get();
int favouriteMorphIndex = currentMorphGui.get().getMorphIndex();
if (favouriteMorphIndex < 0)
System.out.println("Yo wat");
else {
if (resolved.getFavouriteList().containsMorphItem(resolved.getMorphList().getMorphArrayList().get(favouriteMorphIndex)))
FavouriteNetworkingHelper.removeFavouriteMorph(favouriteMorphIndex);
else
FavouriteNetworkingHelper.addFavouriteMorph(favouriteMorphIndex);
}
}
currentMorphGui.ifPresent(morphGui -> morphGui.onFavouriteChanged());
}
}
if (ClientSetup.USE_ABILITY_KEY.isPressed())
MainNetworkChannel.INSTANCE.sendToServer(new MorphRequestAbilityUsage.MorphRequestAbilityUsagePacket());
}
}
}
use of de.budschie.bmorph.capabilities.IMorphCapability in project BudschieMorphMod by Budschie.
the class FavouriteNetworkingHelper method internalAddFavouriteMorph.
// DRY CODE
private static void internalAddFavouriteMorph(boolean add, int indexInMorphArray) {
PlayerEntity player = Minecraft.getInstance().player;
LazyOptional<IMorphCapability> cap = player.getCapability(MorphCapabilityAttacher.MORPH_CAP);
if (cap.isPresent()) {
IMorphCapability resolved = cap.resolve().get();
if (add)
resolved.getFavouriteList().addFavourite(indexInMorphArray);
else
resolved.getFavouriteList().removeFavourite(indexInMorphArray);
MorphRequestFavouriteChangePacket favouritePacket = new MorphRequestFavouriteChangePacket(add, indexInMorphArray);
MainNetworkChannel.INSTANCE.sendToServer(favouritePacket);
} else {
LOGGER.warn("Can't " + (add ? "add" : "remove") + "morph " + indexInMorphArray + " as a favourite, as the capability for morphs is not loaded yet.");
}
}
Aggregations