use of com.wuest.prefab.proxy.messages.PlayerEntityTagMessage in project MC-Prefab by Brian-Wuest.
the class ModEventHandler method onClone.
/**
* This occurs when a player dies and is used to make sure that a player does not get a duplicate starting house.
* @param event
*/
@SubscribeEvent
public static void onClone(PlayerEvent.Clone event) {
if (event.getEntityPlayer() instanceof EntityPlayerMP) {
// Don't add the tag unless the house item was added. This way it can be added if the feature is turned on.
// When the player is cloned, make sure to copy the tag. If this is not done the item can be given to the player again if they die before the log out and log back in.
NBTTagCompound originalTag = event.getOriginal().getEntityData();
// Use the server configuration to determine if the house should be added for this player.
if (Prefab.proxy.proxyConfiguration.addHouseItem) {
if (originalTag.hasKey(EntityPlayerConfiguration.PLAYER_ENTITY_TAG)) {
NBTTagCompound newPlayerTag = event.getEntityPlayer().getEntityData();
newPlayerTag.setTag(EntityPlayerConfiguration.PLAYER_ENTITY_TAG, originalTag.getTag(EntityPlayerConfiguration.PLAYER_ENTITY_TAG));
// Send the persist tag to the client.
Prefab.network.sendTo(new PlayerEntityTagMessage(originalTag.getCompoundTag(EntityPlayerConfiguration.PLAYER_ENTITY_TAG)), (EntityPlayerMP) event.getEntityPlayer());
}
}
}
}
use of com.wuest.prefab.proxy.messages.PlayerEntityTagMessage in project MC-Prefab by Brian-Wuest.
the class ModEventHandler method PlayerJoinedWorld.
/**
* This event is used to determine if the player should be given the starting house item when they log in.
* @param event The event object.
*/
@SubscribeEvent
public static void PlayerJoinedWorld(EntityJoinWorldEvent event) {
if (!event.getWorld().isRemote && event.getEntity() instanceof EntityPlayerMP) {
System.out.println("Player joined world, checking to see if the house builder should be provided.");
EntityPlayerMP player = (EntityPlayerMP) event.getEntity();
EntityPlayerConfiguration playerConfig = EntityPlayerConfiguration.loadFromEntityData((EntityPlayerMP) event.getEntity());
if (!playerConfig.givenHouseBuilder && Prefab.proxy.proxyConfiguration.addHouseItem) {
ItemStack stack = Prefab.proxy.proxyConfiguration.addModerateHouseInstead ? new ItemStack(ModRegistry.ModerateHouse()) : new ItemStack(ModRegistry.StartHouse());
player.inventory.addItemStackToInventory(stack);
player.inventoryContainer.detectAndSendChanges();
// Make sure to set the tag for this player so they don't get the item again.
playerConfig.givenHouseBuilder = true;
playerConfig.saveToPlayer(player);
}
// Send the persist tag to the client.
Prefab.network.sendTo(new PlayerEntityTagMessage(playerConfig.getModIsPlayerNewTag(player)), player);
}
}
use of com.wuest.prefab.proxy.messages.PlayerEntityTagMessage in project MC-Prefab by Brian-Wuest.
the class HouseConfiguration method ConfigurationSpecificBuildStructure.
/**
* This is used to actually build the structure as it creates the structure instance and calls build structure.
* @param player The player which requested the build.
* @param world The world instance where the build will occur.
* @param hitBlockPos This hit block position.
*/
@Override
protected void ConfigurationSpecificBuildStructure(EntityPlayer player, World world, BlockPos hitBlockPos) {
boolean houseBuilt = true;
if (this.houseStyle == HouseConfiguration.HouseStyle.BASIC) {
// We hit a block, let's start building!!!!!
BlockPos startingPosition = hitBlockPos.up();
// Get the new "North" facing. This is the orientation of
// the house and all building will be based on this.
EnumFacing northFace = this.houseFacing;
// Get the "South" facing of the house to make rotating
// easier.
EnumFacing southFace = northFace.getOpposite();
// Set the "North East" corner.
/*ItemStartHouse.NorthEastCorner = startingPosition.offset(northFace, (int) Math.floor(configuration.houseDepth / 2) + 1)
.offset(northFace.rotateY(), (int) Math.floor(configuration.houseWidth / 2) + 1);*/
HouseConfiguration.NorthEastCorner = startingPosition.offset(southFace).offset(northFace.rotateY());
// Set the "South East" corner.
HouseConfiguration.SouthEastCorner = HouseConfiguration.NorthEastCorner.offset(southFace, this.houseDepth + 1);
// Set the "South West" corner.
HouseConfiguration.SouthWestCorner = HouseConfiguration.SouthEastCorner.offset(northFace.rotateYCCW(), this.houseWidth + 1);
// Set the "North West" corner.
HouseConfiguration.NorthWestCorner = HouseConfiguration.NorthEastCorner.offset(northFace.rotateYCCW(), this.houseWidth + 1);
// Put the starting position in the middle of the house as that's what the rest of the methods expect.
startingPosition = HouseConfiguration.NorthEastCorner.offset(southFace, (int) Math.floor(this.houseDepth / 2) + 1).offset(northFace.rotateYCCW(), (int) Math.floor(this.houseWidth / 2) + 1);
BlockPos endBlockPos = startingPosition.offset(northFace.rotateYCCW(), this.houseWidth + 11).offset(southFace, this.houseDepth + 11).offset(EnumFacing.UP, 15);
// Make sure this structure can be placed here.
if (!BuildingMethods.CheckBuildSpaceForAllowedBlockReplacement(this, world, startingPosition, endBlockPos, player)) {
// Send a message to the player saying that the structure could not
// be built.
player.sendMessage(new TextComponentTranslation(GuiLangKeys.GUI_STRUCTURE_NOBUILD).setStyle(new Style().setColor(TextFormatting.GREEN)));
return;
}
// Clear the space before the user is teleported. This
// is in-case they right-click on a space that is only 1
// block tall.
BuildingMethods.ClearSpace(world, HouseConfiguration.NorthEastCorner, this.houseWidth, 15, this.houseDepth, northFace);
// Build the basic structure.
HouseConfiguration.BuildStructure(world, startingPosition, this, northFace);
// Build the interior.
HouseConfiguration.BuildInterior(world, startingPosition, player, this, northFace);
// Set up the exterior.
HouseConfiguration.BuildExterior(world, startingPosition, player, this, northFace);
if (this.addMineShaft && startingPosition.getY() > 15) {
// Set up the mineshaft.
HouseConfiguration.PlaceMineShaft(world, startingPosition, this.houseDepth, northFace);
}
houseBuilt = true;
} else {
// Build the alternate starter house instead.
StructureAlternateStart structure = StructureAlternateStart.CreateInstance(this.houseStyle.getStructureLocation(), StructureAlternateStart.class);
houseBuilt = structure.BuildStructure(this, world, hitBlockPos, EnumFacing.NORTH, player);
}
// The house was successfully built, remove the item from the inventory.
if (houseBuilt) {
EntityPlayerConfiguration playerConfig = EntityPlayerConfiguration.loadFromEntityData((EntityPlayerMP) player);
playerConfig.builtStarterHouse = true;
playerConfig.saveToPlayer(player);
player.inventory.clearMatchingItems(ModRegistry.StartHouse(), -1, 1, null);
player.inventoryContainer.detectAndSendChanges();
// Make sure to send a message to the client to sync up the server player information and the client player information.
Prefab.network.sendTo(new PlayerEntityTagMessage(playerConfig.getModIsPlayerNewTag(player)), (EntityPlayerMP) player);
}
}
Aggregations