mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-17 19:05:16 +00:00
Many cleanups around the wand of the forest, tweaks to force relays
* Split stuff out of the monster main method * Wand must now be in bind mode to act on force relays * Right clicking a force relay in function mode now shows the existing binding, if any
This commit is contained in:
1 parent
90aba57049
commit
7306492adf
4 files changed
+139
-100
No files matched your search
@@ -36,6 +36,7 @@ import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = LibMisc.MOD_ID)
|
||||
public final class BlockHighlightRenderHandler {
|
||||
@@ -54,28 +55,25 @@ public final class BlockHighlightRenderHandler {
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
boundTile: {
|
||||
if(Botania.proxy.isClientPlayerWearingMonocle() && pos != null && pos.getType() == RayTraceResult.Type.BLOCK) {
|
||||
BlockPos bPos = ((BlockRayTraceResult) pos).getPos();
|
||||
if (Botania.proxy.isClientPlayerWearingMonocle() && pos != null && pos.getType() == RayTraceResult.Type.BLOCK) {
|
||||
BlockPos bPos = ((BlockRayTraceResult) pos).getPos();
|
||||
|
||||
ItemStack stackHeld = PlayerHelper.getFirstHeldItem(mc.player, ModItems.twigWand);
|
||||
if(!stackHeld.isEmpty() && ItemTwigWand.getBindMode(stackHeld)) {
|
||||
BlockPos coords = ItemTwigWand.getBoundTile(stackHeld);
|
||||
if(coords.getY() != -1)
|
||||
bPos = coords;
|
||||
}
|
||||
ItemStack stackHeld = PlayerHelper.getFirstHeldItem(mc.player, ModItems.twigWand);
|
||||
if (!stackHeld.isEmpty() && ItemTwigWand.getBindMode(stackHeld)) {
|
||||
Optional<BlockPos> coords = ItemTwigWand.getBindingAttempt(stackHeld);
|
||||
if (coords.isPresent())
|
||||
bPos = coords.get();
|
||||
}
|
||||
|
||||
TileEntity tile = mc.world.getTileEntity(bPos);
|
||||
if(!(tile instanceof TileEntitySpecialFlower))
|
||||
break boundTile;
|
||||
TileEntity tile = mc.world.getTileEntity(bPos);
|
||||
if (tile instanceof TileEntitySpecialFlower) {
|
||||
TileEntitySpecialFlower subtile = (TileEntitySpecialFlower) tile;
|
||||
RadiusDescriptor descriptor = subtile.getRadius();
|
||||
if(descriptor == null)
|
||||
break boundTile;
|
||||
|
||||
if(descriptor.isCircle())
|
||||
renderCircle(descriptor.getSubtileCoords(), descriptor.getCircleRadius());
|
||||
else renderRectangle(descriptor.getAABB(), true, null, (byte) 32);
|
||||
if (descriptor != null) {
|
||||
if (descriptor.isCircle())
|
||||
renderCircle(descriptor.getSubtileCoords(), descriptor.getCircleRadius());
|
||||
else renderRectangle(descriptor.getAABB(), true, null, (byte) 32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,9 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
import vazkii.botania.api.wand.IWandable;
|
||||
import vazkii.botania.common.core.handler.ModSounds;
|
||||
import vazkii.botania.common.item.ItemTwigWand;
|
||||
import vazkii.botania.common.network.PacketBotaniaEffect;
|
||||
import vazkii.botania.common.network.PacketHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
@@ -106,12 +109,22 @@ public class BlockPistonRelay extends BlockMod implements IWandable {
|
||||
return false;
|
||||
|
||||
if(!player.isSneaking()) {
|
||||
activeBindingAttempts.put(player.getUniqueID(), GlobalPos.of(world.getDimension().getType(), pos));
|
||||
world.playSound(null, pos, ModSounds.ding, SoundCategory.BLOCKS, 0.5F, 1F);
|
||||
GlobalPos clicked = GlobalPos.of(world.getDimension().getType(), pos);
|
||||
if(ItemTwigWand.getBindMode(stack)) {
|
||||
activeBindingAttempts.put(player.getUniqueID(), clicked);
|
||||
world.playSound(null, pos, ModSounds.ding, SoundCategory.BLOCKS, 0.5F, 1F);
|
||||
} else {
|
||||
GlobalPos dest = mappedPositions.get(clicked);
|
||||
if (dest != null) {
|
||||
PacketHandler.sendToNearby(world, pos,
|
||||
new PacketBotaniaEffect(PacketBotaniaEffect.EffectType.PARTICLE_BEAM,
|
||||
pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
|
||||
dest.getPos().getX(), dest.getPos().getY(), dest.getPos().getZ()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
spawnAsEntity(world, pos, new ItemStack(this));
|
||||
world.removeBlock(pos, false);
|
||||
world.playEvent(2001, pos, Block.getStateId(getDefaultState()));
|
||||
world.destroyBlock(pos, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -67,6 +67,7 @@ import vazkii.botania.common.network.PacketHandler;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ItemTwigWand extends ItemMod implements ICoordBoundItem {
|
||||
|
||||
@@ -83,6 +84,89 @@ public class ItemTwigWand extends ItemMod implements ICoordBoundItem {
|
||||
addPropertyOverride(new ResourceLocation("botania", "bindmode"), (stack, worldIn, entityIn) -> getBindMode(stack) ? 1 : 0);
|
||||
}
|
||||
|
||||
private static boolean tryCompleteBinding(BlockPos src, ItemStack stack, ItemUseContext ctx) {
|
||||
BlockPos dest = ctx.getPos();
|
||||
if(!dest.equals(src)) {
|
||||
setBindingAttempt(stack, UNBOUND_POS);
|
||||
|
||||
TileEntity srcTile = ctx.getWorld().getTileEntity(src);
|
||||
if (srcTile instanceof IWandBindable) {
|
||||
if(((IWandBindable) srcTile).bindTo(ctx.getPlayer(), stack, dest, ctx.getFace())) {
|
||||
doParticleBeamWithOffset(ctx.getWorld(), src, dest);
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(ctx.getWorld(), src);
|
||||
setBindingAttempt(stack, UNBOUND_POS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean tryFormEnchanter(ItemUseContext ctx) {
|
||||
World world = ctx.getWorld();
|
||||
BlockPos pos = ctx.getPos();
|
||||
Direction.Axis axis = null;
|
||||
if(TileEnchanter.canEnchanterExist(world, pos, Direction.Axis.X))
|
||||
axis = Direction.Axis.X;
|
||||
else if(TileEnchanter.canEnchanterExist(world, pos, Direction.Axis.Z))
|
||||
axis = Direction.Axis.Z;
|
||||
|
||||
if(axis != null) {
|
||||
if(!world.isRemote) {
|
||||
world.setBlockState(pos, ModBlocks.enchanter.getDefaultState().with(BotaniaStateProps.ENCHANTER_DIRECTION, axis), 1 | 2);
|
||||
world.playSound(null, pos, ModSounds.enchanterForm, SoundCategory.BLOCKS, 0.5F, 0.6F);
|
||||
PlayerHelper.grantCriterion((ServerPlayerEntity) ctx.getPlayer(), new ResourceLocation(LibMisc.MOD_ID, "main/enchanter_make"), "code_triggered");
|
||||
} else {
|
||||
for(int i = 0; i < 50; i++) {
|
||||
float red = (float) Math.random();
|
||||
float green = (float) Math.random();
|
||||
float blue = (float) Math.random();
|
||||
|
||||
double x = (Math.random() - 0.5) * 6;
|
||||
double y = (Math.random() - 0.5) * 6;
|
||||
double z = (Math.random() - 0.5) * 6;
|
||||
|
||||
float velMul = 0.07F;
|
||||
|
||||
float motionx = (float) -x * velMul;
|
||||
float motiony = (float) -y * velMul;
|
||||
float motionz = (float) -z * velMul;
|
||||
WispParticleData data = WispParticleData.wisp((float) Math.random() * 0.15F + 0.15F, red, green, blue);
|
||||
world.addParticle(data, pos.getX() + 0.5 + x, pos.getY() + 0.5 + y, pos.getZ() + 0.5 + z, motionx, motiony, motionz);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean tryCompletePistonRelayBinding(ItemUseContext ctx) {
|
||||
World world = ctx.getWorld();
|
||||
BlockPos pos = ctx.getPos();
|
||||
PlayerEntity player = ctx.getPlayer();
|
||||
|
||||
if(((BlockPistonRelay) ModBlocks.pistonRelay).activeBindingAttempts.containsKey(player.getUniqueID())) {
|
||||
GlobalPos bindPos = ((BlockPistonRelay) ModBlocks.pistonRelay).activeBindingAttempts.get(player.getUniqueID());
|
||||
GlobalPos currentPos = GlobalPos.of(world.getDimension().getType(), pos);
|
||||
|
||||
((BlockPistonRelay) ModBlocks.pistonRelay).activeBindingAttempts.remove(player.getUniqueID());
|
||||
((BlockPistonRelay) ModBlocks.pistonRelay).mappedPositions.put(bindPos, currentPos);
|
||||
BlockPistonRelay.WorldData.get(world).markDirty();
|
||||
|
||||
if(bindPos.getDimension() == currentPos.getDimension()) {
|
||||
PacketHandler.sendToNearby(world, pos,
|
||||
new PacketBotaniaEffect(PacketBotaniaEffect.EffectType.PARTICLE_BEAM,
|
||||
bindPos.getPos().getX() + 0.5, bindPos.getPos().getY() + 0.5, bindPos.getPos().getZ() + 0.5,
|
||||
pos.getX(), pos.getY(), pos.getZ()));
|
||||
}
|
||||
|
||||
world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.ding, SoundCategory.PLAYERS, 1F, 1F);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ActionResultType onItemUse(ItemUseContext ctx) {
|
||||
@@ -93,27 +177,14 @@ public class ItemTwigWand extends ItemMod implements ICoordBoundItem {
|
||||
BlockState state = world.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
Direction side = ctx.getFace();
|
||||
|
||||
BlockPos boundPos = getBoundTile(stack);
|
||||
TileEntity boundTile = world.getTileEntity(boundPos);
|
||||
Optional<BlockPos> boundPos = getBindingAttempt(stack);
|
||||
|
||||
if(player == null)
|
||||
return ActionResultType.PASS;
|
||||
|
||||
if(player.isSneaking()) {
|
||||
// Try to complete a binding
|
||||
if(boundPos.getY() != -1 && !pos.equals(boundPos)) {
|
||||
if (boundTile instanceof IWandBindable) {
|
||||
if(((IWandBindable) boundTile).bindTo(player, stack, pos, side)) {
|
||||
doParticleBeamWithOffset(world, boundPos, pos);
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(world, boundPos);
|
||||
setBoundTile(stack, UNBOUND_POS);
|
||||
}
|
||||
|
||||
return ActionResultType.SUCCESS;
|
||||
} else {
|
||||
setBoundTile(stack, UNBOUND_POS);
|
||||
}
|
||||
if (boundPos.isPresent() && tryCompleteBinding(boundPos.get(), stack, ctx)) {
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
if(player.canPlayerEdit(pos, side, stack)
|
||||
@@ -126,40 +197,8 @@ public class ItemTwigWand extends ItemMod implements ICoordBoundItem {
|
||||
}
|
||||
}
|
||||
|
||||
if(block == Blocks.LAPIS_BLOCK && ConfigHandler.COMMON.enchanterEnabled.get()) {
|
||||
Direction.Axis axis = null;
|
||||
if(TileEnchanter.canEnchanterExist(world, pos, Direction.Axis.X))
|
||||
axis = Direction.Axis.X;
|
||||
else if(TileEnchanter.canEnchanterExist(world, pos, Direction.Axis.Z))
|
||||
axis = Direction.Axis.Z;
|
||||
|
||||
if(axis != null) {
|
||||
if(!world.isRemote) {
|
||||
world.setBlockState(pos, ModBlocks.enchanter.getDefaultState().with(BotaniaStateProps.ENCHANTER_DIRECTION, axis), 1 | 2);
|
||||
world.playSound(null, pos, ModSounds.enchanterForm, SoundCategory.BLOCKS, 0.5F, 0.6F);
|
||||
PlayerHelper.grantCriterion((ServerPlayerEntity) player, new ResourceLocation(LibMisc.MOD_ID, "main/enchanter_make"), "code_triggered");
|
||||
} else {
|
||||
for(int i = 0; i < 50; i++) {
|
||||
float red = (float) Math.random();
|
||||
float green = (float) Math.random();
|
||||
float blue = (float) Math.random();
|
||||
|
||||
double x = (Math.random() - 0.5) * 6;
|
||||
double y = (Math.random() - 0.5) * 6;
|
||||
double z = (Math.random() - 0.5) * 6;
|
||||
|
||||
float velMul = 0.07F;
|
||||
|
||||
float motionx = (float) -x * velMul;
|
||||
float motiony = (float) -y * velMul;
|
||||
float motionz = (float) -z * velMul;
|
||||
WispParticleData data = WispParticleData.wisp((float) Math.random() * 0.15F + 0.15F, red, green, blue);
|
||||
world.addParticle(data, pos.getX() + 0.5 + x, pos.getY() + 0.5 + y, pos.getZ() + 0.5 + z, motionx, motiony, motionz);
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
if(block == Blocks.LAPIS_BLOCK && ConfigHandler.COMMON.enchanterEnabled.get() && tryFormEnchanter(ctx)) {
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
if(block instanceof IWandable) {
|
||||
@@ -168,9 +207,9 @@ public class ItemTwigWand extends ItemMod implements ICoordBoundItem {
|
||||
|
||||
boolean wanded;
|
||||
if(getBindMode(stack) && bindable && player.isSneaking() && ((IWandBindable) tile).canSelect(player, stack, pos, side)) {
|
||||
if(boundPos.equals(pos))
|
||||
setBoundTile(stack, UNBOUND_POS);
|
||||
else setBoundTile(stack, pos);
|
||||
if(boundPos.isPresent() && boundPos.get().equals(pos))
|
||||
setBindingAttempt(stack, UNBOUND_POS);
|
||||
else setBindingAttempt(stack, pos);
|
||||
|
||||
if(world.isRemote) {
|
||||
player.playSound(ModSounds.ding, 0.11F, 1F);
|
||||
@@ -184,19 +223,7 @@ public class ItemTwigWand extends ItemMod implements ICoordBoundItem {
|
||||
return wanded ? ActionResultType.SUCCESS : ActionResultType.FAIL;
|
||||
}
|
||||
|
||||
if(!world.isRemote && ((BlockPistonRelay) ModBlocks.pistonRelay).activeBindingAttempts.containsKey(player.getUniqueID())) {
|
||||
GlobalPos bindPos = ((BlockPistonRelay) ModBlocks.pistonRelay).activeBindingAttempts.get(player.getUniqueID());
|
||||
GlobalPos currentPos = GlobalPos.of(world.getDimension().getType(), pos);
|
||||
|
||||
((BlockPistonRelay) ModBlocks.pistonRelay).activeBindingAttempts.remove(player.getUniqueID());
|
||||
((BlockPistonRelay) ModBlocks.pistonRelay).mappedPositions.put(bindPos, currentPos);
|
||||
BlockPistonRelay.WorldData.get(world).markDirty();
|
||||
|
||||
PacketHandler.sendToNearby(world, pos,
|
||||
new PacketBotaniaEffect(PacketBotaniaEffect.EffectType.PARTICLE_BEAM,
|
||||
bindPos.getPos().getX() + 0.5, bindPos.getPos().getY() + 0.5, bindPos.getPos().getZ() + 0.5,
|
||||
pos.getX(), pos.getY(), pos.getZ()));
|
||||
world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.ding, SoundCategory.PLAYERS, 1F, 1F);
|
||||
if(!world.isRemote && getBindMode(stack) && tryCompletePistonRelayBinding(ctx)) {
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
@@ -237,10 +264,11 @@ public class ItemTwigWand extends ItemMod implements ICoordBoundItem {
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack par1ItemStack, World world, Entity par3Entity, int par4, boolean par5) {
|
||||
BlockPos coords = getBoundTile(par1ItemStack);
|
||||
TileEntity tile = world.getTileEntity(coords);
|
||||
if(!(tile instanceof IWandBindable))
|
||||
setBoundTile(par1ItemStack, UNBOUND_POS);
|
||||
getBindingAttempt(par1ItemStack).ifPresent(coords -> {
|
||||
TileEntity tile = world.getTileEntity(coords);
|
||||
if(!(tile instanceof IWandBindable))
|
||||
setBindingAttempt(par1ItemStack, UNBOUND_POS);
|
||||
});
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -292,17 +320,17 @@ public class ItemTwigWand extends ItemMod implements ICoordBoundItem {
|
||||
return ItemNBTHelper.getInt(stack, TAG_COLOR2, 0);
|
||||
}
|
||||
|
||||
public static void setBoundTile(ItemStack stack, BlockPos pos) {
|
||||
public static void setBindingAttempt(ItemStack stack, BlockPos pos) {
|
||||
ItemNBTHelper.setInt(stack, TAG_BOUND_TILE_X, pos.getX());
|
||||
ItemNBTHelper.setInt(stack, TAG_BOUND_TILE_Y, pos.getY());
|
||||
ItemNBTHelper.setInt(stack, TAG_BOUND_TILE_Z, pos.getZ());
|
||||
}
|
||||
|
||||
public static BlockPos getBoundTile(ItemStack stack) {
|
||||
public static Optional<BlockPos> getBindingAttempt(ItemStack stack) {
|
||||
int x = ItemNBTHelper.getInt(stack, TAG_BOUND_TILE_X, 0);
|
||||
int y = ItemNBTHelper.getInt(stack, TAG_BOUND_TILE_Y, -1);
|
||||
int z = ItemNBTHelper.getInt(stack, TAG_BOUND_TILE_Z, 0);
|
||||
return new BlockPos(x, y, z);
|
||||
return y < 0 ? Optional.empty() : Optional.of(new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
public static boolean getBindMode(ItemStack stack) {
|
||||
@@ -319,9 +347,9 @@ public class ItemTwigWand extends ItemMod implements ICoordBoundItem {
|
||||
|
||||
@Override
|
||||
public BlockPos getBinding(ItemStack stack) {
|
||||
BlockPos bound = getBoundTile(stack);
|
||||
if(bound.getY() != -1)
|
||||
return bound;
|
||||
Optional<BlockPos> bound = getBindingAttempt(stack);
|
||||
if(bound.isPresent())
|
||||
return bound.get();
|
||||
|
||||
RayTraceResult pos = Minecraft.getInstance().objectMouseOver;
|
||||
if(pos != null && pos.getType() == RayTraceResult.Type.BLOCK) {
|
||||
|
||||
Reference in new issue
Block a user