mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Patch dolphin, generify trades, move to dir, trades list repl. one
This commit is contained in:
parent
a3889fe369
commit
a1110a847d
@ -2,30 +2,29 @@ package com.volmit.iris.core;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.engine.object.entity.IrisEntityVillagerOverride;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.engine.object.villager.IrisVillagerOverride;
|
||||
import com.volmit.iris.engine.object.villager.IrisVillagerTrade;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityInteractEvent;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class InteractionManager implements Listener {
|
||||
|
||||
/**
|
||||
* Prevents dolphins from trying to locate a treasure map.
|
||||
* Prevents dolphins from being fed, to locate a treasure map.
|
||||
* Note: This results in odd dolphin behaviour, but it's the best we can do.
|
||||
*/
|
||||
@EventHandler
|
||||
public void on(EntityPickupItemEvent event){
|
||||
if (!IrisToolbelt.isIrisWorld(event.getEntity().getWorld())){
|
||||
public void on(PlayerInteractEntityEvent event){
|
||||
if (!IrisToolbelt.isIrisWorld(event.getPlayer().getWorld())){
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getEntityType().equals(EntityType.DOLPHIN)){
|
||||
Material hand = event.getPlayer().getInventory().getItem(event.getHand()).getType();
|
||||
if (event.getRightClicked().getType().equals(EntityType.DOLPHIN) && (hand.equals(Material.TROPICAL_FISH) || hand.equals(Material.PUFFERFISH) || hand.equals(Material.COD) || hand.equals(Material.SALMON))){
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -41,7 +40,7 @@ public class InteractionManager implements Listener {
|
||||
|
||||
// Iris.info("Trade event: type " + event.getRecipe().getResult().getType() + " / meta " + event.getRecipe().getResult().getItemMeta() + " / data " + event.getRecipe().getResult().getData());
|
||||
if (event.getRecipe().getResult().getType().equals(Material.FILLED_MAP)){
|
||||
IrisEntityVillagerOverride override = IrisToolbelt.access(event.getEntity().getWorld()).getCompound().getRootDimension().getVillagerTrade();
|
||||
IrisVillagerOverride override = IrisToolbelt.access(event.getEntity().getWorld()).getCompound().getRootDimension().getPatchCartographers();
|
||||
|
||||
if (override.isDisableTrade()){
|
||||
event.setCancelled(true);
|
||||
@ -49,16 +48,15 @@ public class InteractionManager implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!override.getItems().isValidItems()){
|
||||
if (override.getValidItems() == null){
|
||||
event.setCancelled(true);
|
||||
Iris.debug("Cancelled cartographer trade because override items not valid @ " + event.getEntity().getLocation());
|
||||
Iris.debug("Cancelled cartographer trade because no override items are valid @ " + event.getEntity().getLocation());
|
||||
return;
|
||||
}
|
||||
|
||||
MerchantRecipe recipe = new MerchantRecipe(override.getItems().getResult(), override.getItems().getAmount());
|
||||
recipe.setIngredients(override.getItems().getIngredients());
|
||||
event.setRecipe(recipe);
|
||||
Iris.debug("Overrode cartographer trade with: " + recipe + " to prevent allowing cartography map trades");
|
||||
IrisVillagerTrade trade = override.getValidItems().getRandom();
|
||||
event.setRecipe(trade.convert());
|
||||
Iris.debug("Overrode cartographer trade with: " + trade + " to prevent allowing cartography map trades");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ import com.volmit.iris.engine.object.carve.IrisCaveFluid;
|
||||
import com.volmit.iris.engine.object.carve.IrisCaveLayer;
|
||||
import com.volmit.iris.engine.object.carve.IrisCaverns;
|
||||
import com.volmit.iris.engine.object.deposits.IrisDepositGenerator;
|
||||
import com.volmit.iris.engine.object.entity.IrisEntityVillagerOverride;
|
||||
import com.volmit.iris.engine.object.villager.IrisVillagerOverride;
|
||||
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
|
||||
import com.volmit.iris.engine.object.feature.IrisFeaturePotential;
|
||||
import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructure;
|
||||
@ -332,7 +332,7 @@ public class IrisDimension extends IrisRegistrant {
|
||||
private KList<IrisBiomeMutation> mutations = new KList<>();
|
||||
|
||||
@Desc("Cartographer map trade overrides")
|
||||
private IrisEntityVillagerOverride patchCartographers = new IrisEntityVillagerOverride().setDisableTrade(false);
|
||||
private IrisVillagerOverride patchCartographers = new IrisVillagerOverride().setDisableTrade(false);
|
||||
|
||||
private final transient AtomicCache<Position2> parallaxSize = new AtomicCache<>();
|
||||
private final transient AtomicCache<CNG> rockLayerGenerator = new AtomicCache<>();
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.volmit.iris.engine.object.entity;
|
||||
package com.volmit.iris.engine.object.villager;
|
||||
|
||||
import com.volmit.iris.engine.object.annotations.ArrayType;
|
||||
import com.volmit.iris.engine.object.annotations.DependsOn;
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.iris.engine.object.annotations.Required;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -18,7 +20,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
@Desc("Override cartographer map trades with others or disable the trade altogether")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisEntityVillagerOverride {
|
||||
public class IrisVillagerOverride {
|
||||
@Desc("""
|
||||
Disable the trade altogether.
|
||||
If a cartographer villager gets a new explorer map trade:
|
||||
@ -33,10 +35,17 @@ public class IrisEntityVillagerOverride {
|
||||
The items to override the cartographer trade with.
|
||||
By default, this is 3 emeralds + 3 glass blocks -> 1 spyglass.
|
||||
Can trade 3 to 5 times""")
|
||||
private IrisEntityVillagerOverrideItems items = new IrisEntityVillagerOverrideItems()
|
||||
@ArrayType(min = 1, type = IrisVillagerTrade.class)
|
||||
private KList<IrisVillagerTrade> items = new KList<>(new IrisVillagerTrade()
|
||||
.setIngredient1(new ItemStack(Material.EMERALD, 3))
|
||||
.setIngredient2(new ItemStack(Material.GLASS, 3))
|
||||
.setResult(new ItemStack(Material.SPYGLASS))
|
||||
.setMinTrades(3)
|
||||
.setMaxTrades(5);
|
||||
.setMaxTrades(5));
|
||||
|
||||
public KList<IrisVillagerTrade> getValidItems(){
|
||||
KList<IrisVillagerTrade> valid = new KList<>();
|
||||
getItems().stream().filter(IrisVillagerTrade::isValidItems).forEach(valid::add);
|
||||
return valid.size() == 0 ? null : valid;
|
||||
}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package com.volmit.iris.engine.object.entity;
|
||||
package com.volmit.iris.engine.object.villager;
|
||||
|
||||
|
||||
import com.volmit.iris.engine.object.annotations.*;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@ -10,6 +11,7 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -19,10 +21,10 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
@Desc("Override cartographer map trades with these items. ")
|
||||
@Desc("Represents a villager trade.")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisEntityVillagerOverrideItems {
|
||||
public class IrisVillagerTrade {
|
||||
|
||||
@Required
|
||||
@RegistryListItemType
|
||||
@ -78,4 +80,13 @@ public class IrisEntityVillagerOverrideItems {
|
||||
public int getAmount() {
|
||||
return RNG.r.i(minTrades, maxTrades);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the trade as a merchant recipe
|
||||
*/
|
||||
public MerchantRecipe convert(){
|
||||
MerchantRecipe recipe = new MerchantRecipe(getResult(), getAmount());
|
||||
recipe.setIngredients(getIngredients());
|
||||
return recipe;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user