- 124
- 1
- 0
Добрый день мододелы, подскажите как сделать динамический источник света, который привязан к entity. Необходимо освещать территорию в радиусе 3-4 блока вокруг определённых игроков.
Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
@SubscribeEvent
public void onPlayerMove(LivingUpdateEvent e)
{
if (e.entityLiving instanceof EntityPlayer)
{
EntityPlayer p = (EntityPlayer) e.entityLiving;
if (!p.worldObj.isRemote)
{
if (ModLights.hasLitLanternOnHotbar(p.inventory))
{
Pos3 pos = new Pos3(MathHelper.floor_double(p.posX), MathHelper.floor_double(p.posY) + 1, MathHelper.floor_double(p.posZ));
if (p.ridingEntity != null)
{
pos = new Pos3(MathHelper.floor_double(p.ridingEntity.posX), MathHelper.floor_double(p.ridingEntity.posY) + 1, MathHelper.floor_double(p.ridingEntity.posZ));
}
if (p.worldObj.getBlock(pos.x, pos.y, pos.z).equals(Blocks.air))
{
p.worldObj.setBlock(pos.x, pos.y, pos.z, ModLights.Lantern);
}
if (ModLights.usernameLastPosMap.containsKey(p.getDisplayName()))
{
Pos3 pos2 = ModLights.usernameLastPosMap.get(p.getDisplayName());
if ((pos2.x != pos.x || pos2.y != pos.y || pos2.z != pos.z) && p.worldObj.getBlock(pos2.x, pos2.y, pos2.z).equals(ModLights.Lantern))
{
p.worldObj.setBlock(pos2.x, pos2.y, pos2.z, Blocks.air);
}
}
ModLights.usernameLastPosMap.put(p.getDisplayName(), pos);
}
else
{
if (ModLights.usernameLastPosMap.containsKey(p.getDisplayName()))
{
Pos3 pos = ModLights.usernameLastPosMap.get(p.getDisplayName());
if (p.worldObj.getBlock(pos.x, pos.y, pos.z).equals(ModLights.Lantern))
{
p.worldObj.setBlock(pos.x, pos.y, pos.z, Blocks.air);
}
ModLights.usernameLastPosMap.remove(p.getDisplayName());
}
}
}
}
}
Вот это у меня в ModLights проверка на наличия в инвентаре
public static HashMap<String, Pos3> usernameLastPosMap = new HashMap<String, Pos3>();
public static boolean hasLitLanternOnHotbar(InventoryPlayer inv)
{
for (int i = 0; i < 9; i++)
{
ItemStack item = inv.mainInventory[i];
if (item != null && item.getItem() == ItemLanterns)
{
return true;
}
}
return false;
}
Это дикие костыли. А как же, когда игрок через дверь проходит, к примеру?)Не помню мода может и сумеречный
svk2140 Вот код от фонарика работает нормально
Код:@SubscribeEvent public void onPlayerMove(LivingUpdateEvent e) { if (e.entityLiving instanceof EntityPlayer) { EntityPlayer p = (EntityPlayer) e.entityLiving; if (!p.worldObj.isRemote) { if (ModLights.hasLitLanternOnHotbar(p.inventory)) { Pos3 pos = new Pos3(MathHelper.floor_double(p.posX), MathHelper.floor_double(p.posY) + 1, MathHelper.floor_double(p.posZ)); if (p.ridingEntity != null) { pos = new Pos3(MathHelper.floor_double(p.ridingEntity.posX), MathHelper.floor_double(p.ridingEntity.posY) + 1, MathHelper.floor_double(p.ridingEntity.posZ)); } if (p.worldObj.getBlock(pos.x, pos.y, pos.z).equals(Blocks.air)) { p.worldObj.setBlock(pos.x, pos.y, pos.z, ModLights.Lantern); } if (ModLights.usernameLastPosMap.containsKey(p.getDisplayName())) { Pos3 pos2 = ModLights.usernameLastPosMap.get(p.getDisplayName()); if ((pos2.x != pos.x || pos2.y != pos.y || pos2.z != pos.z) && p.worldObj.getBlock(pos2.x, pos2.y, pos2.z).equals(ModLights.Lantern)) { p.worldObj.setBlock(pos2.x, pos2.y, pos2.z, Blocks.air); } } ModLights.usernameLastPosMap.put(p.getDisplayName(), pos); } else { if (ModLights.usernameLastPosMap.containsKey(p.getDisplayName())) { Pos3 pos = ModLights.usernameLastPosMap.get(p.getDisplayName()); if (p.worldObj.getBlock(pos.x, pos.y, pos.z).equals(ModLights.Lantern)) { p.worldObj.setBlock(pos.x, pos.y, pos.z, Blocks.air); } ModLights.usernameLastPosMap.remove(p.getDisplayName()); } } } } }
Код:Вот это у меня в ModLights проверка на наличия в инвентаре public static HashMap<String, Pos3> usernameLastPosMap = new HashMap<String, Pos3>(); public static boolean hasLitLanternOnHotbar(InventoryPlayer inv) { for (int i = 0; i < 9; i++) { ItemStack item = inv.mainInventory[i]; if (item != null && item.getItem() == ItemLanterns) { return true; } } return false; }
Ну, собственно, так оно и решается.спец. шейдеры
динамикслайт тупо блоки ставитЕсть мод DynamicLights. Он опенсурс.