use of com.bewitchment.api.cauldron.brew.IBrew in project Bewitchment by Um-Mitternacht.
the class BrewUtils method getBrewsFromStack.
public static List<BrewEffect> getBrewsFromStack(ItemStack stack) {
List<BrewEffect> effects = new ArrayList<>();
NBTTagList list = NBTHelper.getNBT(stack, BREW_DATA);
for (int i = 0, size = list.tagCount(); i < size; i++) {
NBTTagCompound tag = list.getCompoundTagAt(i);
IBrew brew = BrewRegistry.getRegisteredBrew(tag.getString(BREW_ID));
int duration = tag.getInteger(BREW_DURATION);
int amplifier = tag.getInteger(BREW_AMPLIFIER);
effects.add(new BrewEffect(brew, duration, amplifier));
}
return effects;
}
use of com.bewitchment.api.cauldron.brew.IBrew in project Bewitchment by Um-Mitternacht.
the class BrewHUD method renderOverlay.
@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent.Post event) {
if (!ConfigHandler.CLIENT.BREW_HUD.hide && event.getType() == RenderGameOverlayEvent.ElementType.ALL) {
Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(Minecraft.getMinecraft().player);
if (optional.isPresent()) {
ScaledResolution res = event.getResolution();
int xOffset = res.getScaledWidth() - ConfigHandler.CLIENT.BREW_HUD.x;
int yOffset = ConfigHandler.CLIENT.BREW_HUD.y;
Minecraft mc = Minecraft.getMinecraft();
Collection<BrewEffect> effects = optional.get().getBrewEffects();
if (effects.isEmpty())
return;
for (BrewEffect effect : effects) {
IBrew brew = effect.getBrew();
if (brew.shouldRender()) {
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
brew.renderHUD(xOffset, yOffset, mc, effect.getAmplifier());
if (ConfigHandler.CLIENT.BREW_HUD.orientation) {
yOffset += 22;
} else {
xOffset += 22;
}
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
}
}
}
}
use of com.bewitchment.api.cauldron.brew.IBrew in project Bewitchment by Um-Mitternacht.
the class BrewEvents method onUpdate.
@SubscribeEvent
public void onUpdate(LivingEvent.LivingUpdateEvent event) {
EntityLivingBase entity = event.getEntityLiving();
Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(entity);
if (optional.isPresent()) {
IBrewStorage storage = optional.get();
Map<IBrew, BrewEffect> brews = storage.getBrewMap();
if (brews.isEmpty())
return;
boolean update = false;
if (!entity.world.isRemote && BrewStorageHandler.BREW_REMOVAL.containsKey(entity)) {
for (IBrew brew : BrewStorageHandler.BREW_REMOVAL.get(entity)) {
brews.get(brew).end(entity.world, entity.getPosition(), entity);
brews.remove(brew);
}
BrewStorageHandler.BREW_REMOVAL.remove(entity);
update = true;
}
Map<IBrew, BrewEffect> updated = new HashMap<>();
for (BrewEffect effect : brews.values()) {
if (effect.getDuration() <= 0) {
effect.end(entity.world, entity.getPosition(), entity);
update = true;
} else {
effect.update(entity.world, entity.getPosition(), entity);
updated.put(effect.getBrew(), effect);
}
}
if (!entity.world.isRemote) {
storage.setBrewMap(updated);
if (update) {
storage.syncToNear(entity);
}
}
}
}
use of com.bewitchment.api.cauldron.brew.IBrew in project Bewitchment by Um-Mitternacht.
the class BrewMessage method fromBytes.
@Override
public void fromBytes(ByteBuf buf) {
target = new UUID(buf.readLong(), buf.readLong());
int size = buf.readInt();
effects = new LinkedHashMap<>(size);
for (int i = 0; i < size; i++) {
IBrew brew = BrewRegistry.getBrew(buf.readInt());
effects.put(brew, new BrewEffect(brew, buf.readInt(), buf.readInt()));
}
}
Aggregations